Skip to content

Commit 4fd8c04

Browse files
committed
Auto merge of rust-lang#139336 - matthiaskrgr:rollup-zsi8pgf, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#138017 (Tighten up assignment operator representations.) - rust-lang#138462 (Dedup `&mut *` reborrow suggestion in loops) - rust-lang#138610 (impl !PartialOrd for HirId) - rust-lang#138767 (Allow boolean literals in `check-cfg`) - rust-lang#139068 (io: Avoid marking some bytes as uninit) - rust-lang#139255 (Remove unused variables generated in merged doctests) - rust-lang#139270 (Add a mailmap entry for myself) - rust-lang#139303 (Put Noratrieb on vacation) - rust-lang#139312 (add Marco Ieni to mailmap) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 00095b3 + 4cf6c21 commit 4fd8c04

File tree

81 files changed

+806
-598
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+806
-598
lines changed

.mailmap

+5-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ Jacob Greenfield <[email protected]>
276276
277277
278278
Jake Goulding <[email protected]>
279-
279+
280280
281281
Jake Vossen <[email protected]>
282282
@@ -412,6 +412,7 @@ Malo Jaffré <[email protected]>
412412
Manish Goregaokar <[email protected]>
413413
414414
Marcell Pardavi <[email protected]>
415+
Marco Ieni <[email protected]>
415416
Marcus Klaas de Vries <[email protected]>
416417
Margaret Meyerhofer <[email protected]> <mmeyerho@andrew>
417418
Mark Mansi <[email protected]>
@@ -565,6 +566,9 @@ Robert Habermeier <[email protected]>
565566
Robert Millar <[email protected]>
566567
567568
Rohit Joshi <[email protected]> Rohit Joshi <[email protected]>
569+
Ross Smyth <[email protected]>
570+
571+
568572
Roxane Fruytier <[email protected]>
569573
570574
Russell Johnston <[email protected]>

compiler/rustc_ast/src/ast.rs

+70-1
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,75 @@ impl BinOpKind {
981981

982982
pub type BinOp = Spanned<BinOpKind>;
983983

984+
// Sometimes `BinOpKind` and `AssignOpKind` need the same treatment. The
985+
// operations covered by `AssignOpKind` are a subset of those covered by
986+
// `BinOpKind`, so it makes sense to convert `AssignOpKind` to `BinOpKind`.
987+
impl From<AssignOpKind> for BinOpKind {
988+
fn from(op: AssignOpKind) -> BinOpKind {
989+
match op {
990+
AssignOpKind::AddAssign => BinOpKind::Add,
991+
AssignOpKind::SubAssign => BinOpKind::Sub,
992+
AssignOpKind::MulAssign => BinOpKind::Mul,
993+
AssignOpKind::DivAssign => BinOpKind::Div,
994+
AssignOpKind::RemAssign => BinOpKind::Rem,
995+
AssignOpKind::BitXorAssign => BinOpKind::BitXor,
996+
AssignOpKind::BitAndAssign => BinOpKind::BitAnd,
997+
AssignOpKind::BitOrAssign => BinOpKind::BitOr,
998+
AssignOpKind::ShlAssign => BinOpKind::Shl,
999+
AssignOpKind::ShrAssign => BinOpKind::Shr,
1000+
}
1001+
}
1002+
}
1003+
1004+
#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
1005+
pub enum AssignOpKind {
1006+
/// The `+=` operator (addition)
1007+
AddAssign,
1008+
/// The `-=` operator (subtraction)
1009+
SubAssign,
1010+
/// The `*=` operator (multiplication)
1011+
MulAssign,
1012+
/// The `/=` operator (division)
1013+
DivAssign,
1014+
/// The `%=` operator (modulus)
1015+
RemAssign,
1016+
/// The `^=` operator (bitwise xor)
1017+
BitXorAssign,
1018+
/// The `&=` operator (bitwise and)
1019+
BitAndAssign,
1020+
/// The `|=` operator (bitwise or)
1021+
BitOrAssign,
1022+
/// The `<<=` operator (shift left)
1023+
ShlAssign,
1024+
/// The `>>=` operator (shift right)
1025+
ShrAssign,
1026+
}
1027+
1028+
impl AssignOpKind {
1029+
pub fn as_str(&self) -> &'static str {
1030+
use AssignOpKind::*;
1031+
match self {
1032+
AddAssign => "+=",
1033+
SubAssign => "-=",
1034+
MulAssign => "*=",
1035+
DivAssign => "/=",
1036+
RemAssign => "%=",
1037+
BitXorAssign => "^=",
1038+
BitAndAssign => "&=",
1039+
BitOrAssign => "|=",
1040+
ShlAssign => "<<=",
1041+
ShrAssign => ">>=",
1042+
}
1043+
}
1044+
1045+
/// AssignOps are always by value.
1046+
pub fn is_by_value(self) -> bool {
1047+
true
1048+
}
1049+
}
1050+
1051+
pub type AssignOp = Spanned<AssignOpKind>;
1052+
9841053
/// Unary operator.
9851054
///
9861055
/// Note that `&data` is not an operator, it's an `AddrOf` expression.
@@ -1593,7 +1662,7 @@ pub enum ExprKind {
15931662
/// An assignment with an operator.
15941663
///
15951664
/// E.g., `a += 1`.
1596-
AssignOp(BinOp, P<Expr>, P<Expr>),
1665+
AssignOp(AssignOp, P<Expr>, P<Expr>),
15971666
/// Access of a named (e.g., `obj.foo`) or unnamed (e.g., `obj.0`) struct field.
15981667
Field(P<Expr>, Ident),
15991668
/// An indexing operation (e.g., `foo[2]`).

compiler/rustc_ast/src/attr/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,14 @@ impl MetaItemInner {
570570
}
571571
}
572572

573+
/// Returns the bool if `self` is a boolean `MetaItemInner::Literal`.
574+
pub fn boolean_literal(&self) -> Option<bool> {
575+
match self {
576+
MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => Some(*b),
577+
_ => None,
578+
}
579+
}
580+
573581
/// Returns the `MetaItem` if `self` is a `MetaItemInner::MetaItem` or if it's
574582
/// `MetaItemInner::Lit(MetaItemLit { kind: LitKind::Bool(_), .. })`.
575583
pub fn meta_item_or_bool(&self) -> Option<&MetaItemInner> {

compiler/rustc_ast/src/util/parser.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_span::kw;
22

3-
use crate::ast::{self, BinOpKind, RangeLimits};
3+
use crate::ast::{self, AssignOpKind, BinOpKind, RangeLimits};
44
use crate::token::{self, Token};
55

66
/// Associative operator.
@@ -9,7 +9,7 @@ pub enum AssocOp {
99
/// A binary op.
1010
Binary(BinOpKind),
1111
/// `?=` where ? is one of the assignable BinOps
12-
AssignOp(BinOpKind),
12+
AssignOp(AssignOpKind),
1313
/// `=`
1414
Assign,
1515
/// `as`
@@ -44,16 +44,16 @@ impl AssocOp {
4444
token::Or => Some(Binary(BinOpKind::BitOr)),
4545
token::Shl => Some(Binary(BinOpKind::Shl)),
4646
token::Shr => Some(Binary(BinOpKind::Shr)),
47-
token::PlusEq => Some(AssignOp(BinOpKind::Add)),
48-
token::MinusEq => Some(AssignOp(BinOpKind::Sub)),
49-
token::StarEq => Some(AssignOp(BinOpKind::Mul)),
50-
token::SlashEq => Some(AssignOp(BinOpKind::Div)),
51-
token::PercentEq => Some(AssignOp(BinOpKind::Rem)),
52-
token::CaretEq => Some(AssignOp(BinOpKind::BitXor)),
53-
token::AndEq => Some(AssignOp(BinOpKind::BitAnd)),
54-
token::OrEq => Some(AssignOp(BinOpKind::BitOr)),
55-
token::ShlEq => Some(AssignOp(BinOpKind::Shl)),
56-
token::ShrEq => Some(AssignOp(BinOpKind::Shr)),
47+
token::PlusEq => Some(AssignOp(AssignOpKind::AddAssign)),
48+
token::MinusEq => Some(AssignOp(AssignOpKind::SubAssign)),
49+
token::StarEq => Some(AssignOp(AssignOpKind::MulAssign)),
50+
token::SlashEq => Some(AssignOp(AssignOpKind::DivAssign)),
51+
token::PercentEq => Some(AssignOp(AssignOpKind::RemAssign)),
52+
token::CaretEq => Some(AssignOp(AssignOpKind::BitXorAssign)),
53+
token::AndEq => Some(AssignOp(AssignOpKind::BitAndAssign)),
54+
token::OrEq => Some(AssignOp(AssignOpKind::BitOrAssign)),
55+
token::ShlEq => Some(AssignOp(AssignOpKind::ShlAssign)),
56+
token::ShrEq => Some(AssignOp(AssignOpKind::ShrAssign)),
5757
token::Lt => Some(Binary(BinOpKind::Lt)),
5858
token::Le => Some(Binary(BinOpKind::Le)),
5959
token::Ge => Some(Binary(BinOpKind::Ge)),

compiler/rustc_ast_lowering/src/expr.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
274274
}
275275
ExprKind::Assign(el, er, span) => self.lower_expr_assign(el, er, *span, e.span),
276276
ExprKind::AssignOp(op, el, er) => hir::ExprKind::AssignOp(
277-
self.lower_binop(*op),
277+
self.lower_assign_op(*op),
278278
self.lower_expr(el),
279279
self.lower_expr(er),
280280
),
@@ -443,6 +443,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
443443
Spanned { node: b.node, span: self.lower_span(b.span) }
444444
}
445445

446+
fn lower_assign_op(&mut self, a: AssignOp) -> AssignOp {
447+
Spanned { node: a.node, span: self.lower_span(a.span) }
448+
}
449+
446450
fn lower_legacy_const_generics(
447451
&mut self,
448452
mut f: Expr,

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -274,22 +274,22 @@ impl<'a> State<'a> {
274274

275275
fn print_expr_binary(
276276
&mut self,
277-
op: ast::BinOp,
277+
op: ast::BinOpKind,
278278
lhs: &ast::Expr,
279279
rhs: &ast::Expr,
280280
fixup: FixupContext,
281281
) {
282-
let binop_prec = op.node.precedence();
282+
let binop_prec = op.precedence();
283283
let left_prec = lhs.precedence();
284284
let right_prec = rhs.precedence();
285285

286-
let (mut left_needs_paren, right_needs_paren) = match op.node.fixity() {
286+
let (mut left_needs_paren, right_needs_paren) = match op.fixity() {
287287
Fixity::Left => (left_prec < binop_prec, right_prec <= binop_prec),
288288
Fixity::Right => (left_prec <= binop_prec, right_prec < binop_prec),
289289
Fixity::None => (left_prec <= binop_prec, right_prec <= binop_prec),
290290
};
291291

292-
match (&lhs.kind, op.node) {
292+
match (&lhs.kind, op) {
293293
// These cases need parens: `x as i32 < y` has the parser thinking that `i32 < y` is
294294
// the beginning of a path type. It starts trying to parse `x as (i32 < y ...` instead
295295
// of `(x as i32) < ...`. We need to convince it _not_ to do that.
@@ -312,7 +312,7 @@ impl<'a> State<'a> {
312312

313313
self.print_expr_cond_paren(lhs, left_needs_paren, fixup.leftmost_subexpression());
314314
self.space();
315-
self.word_space(op.node.as_str());
315+
self.word_space(op.as_str());
316316
self.print_expr_cond_paren(rhs, right_needs_paren, fixup.subsequent_subexpression());
317317
}
318318

@@ -410,7 +410,7 @@ impl<'a> State<'a> {
410410
self.print_expr_method_call(seg, receiver, args, fixup);
411411
}
412412
ast::ExprKind::Binary(op, lhs, rhs) => {
413-
self.print_expr_binary(*op, lhs, rhs, fixup);
413+
self.print_expr_binary(op.node, lhs, rhs, fixup);
414414
}
415415
ast::ExprKind::Unary(op, expr) => {
416416
self.print_expr_unary(*op, expr, fixup);
@@ -605,8 +605,7 @@ impl<'a> State<'a> {
605605
fixup.leftmost_subexpression(),
606606
);
607607
self.space();
608-
self.word(op.node.as_str());
609-
self.word_space("=");
608+
self.word_space(op.node.as_str());
610609
self.print_expr_cond_paren(
611610
rhs,
612611
rhs.precedence() < ExprPrecedence::Assign,

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

-13
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
181181
let closure = self.add_moved_or_invoked_closure_note(location, used_place, &mut err);
182182

183183
let mut is_loop_move = false;
184-
let mut in_pattern = false;
185184
let mut seen_spans = FxIndexSet::default();
186185

187186
for move_site in &move_site_vec {
@@ -204,7 +203,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
204203
self.suggest_ref_or_clone(
205204
mpi,
206205
&mut err,
207-
&mut in_pattern,
208206
move_spans,
209207
moved_place.as_ref(),
210208
&mut has_suggest_reborrow,
@@ -256,15 +254,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
256254
let place = &self.move_data.move_paths[mpi].place;
257255
let ty = place.ty(self.body, self.infcx.tcx).ty;
258256

259-
// If we're in pattern, we do nothing in favor of the previous suggestion (#80913).
260-
// Same for if we're in a loop, see #101119.
261-
if is_loop_move & !in_pattern && !matches!(use_spans, UseSpans::ClosureUse { .. }) {
262-
if let ty::Ref(_, _, hir::Mutability::Mut) = ty.kind() {
263-
// We have a `&mut` ref, we need to reborrow on each iteration (#62112).
264-
self.suggest_reborrow(&mut err, span, moved_place);
265-
}
266-
}
267-
268257
if self.infcx.param_env.caller_bounds().iter().any(|c| {
269258
c.as_trait_clause().is_some_and(|pred| {
270259
pred.skip_binder().self_ty() == ty && self.infcx.tcx.is_fn_trait(pred.def_id())
@@ -330,7 +319,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
330319
&self,
331320
mpi: MovePathIndex,
332321
err: &mut Diag<'infcx>,
333-
in_pattern: &mut bool,
334322
move_spans: UseSpans<'tcx>,
335323
moved_place: PlaceRef<'tcx>,
336324
has_suggest_reborrow: &mut bool,
@@ -545,7 +533,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
545533
&& !move_span.is_dummy()
546534
&& !self.infcx.tcx.sess.source_map().is_imported(move_span)
547535
{
548-
*in_pattern = true;
549536
let mut sugg = vec![(pat.span.shrink_to_lo(), "ref ".to_string())];
550537
if let Some(pat) = finder.parent_pat {
551538
sugg.insert(0, (pat.span.shrink_to_lo(), "ref ".to_string()));

compiler/rustc_codegen_ssa/src/back/link.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -959,9 +959,9 @@ fn link_natively(
959959
}
960960
}
961961

962-
let (level, src) = codegen_results.crate_info.lint_levels.linker_messages;
962+
let level = codegen_results.crate_info.lint_levels.linker_messages;
963963
let lint = |msg| {
964-
lint_level(sess, LINKER_MESSAGES, level, src, None, |diag| {
964+
lint_level(sess, LINKER_MESSAGES, level, None, |diag| {
965965
LinkerOutput { inner: msg }.decorate_lint(diag)
966966
})
967967
};

compiler/rustc_codegen_ssa/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use rustc_hir::CRATE_HIR_ID;
3434
use rustc_hir::def_id::CrateNum;
3535
use rustc_macros::{Decodable, Encodable, HashStable};
3636
use rustc_middle::dep_graph::WorkProduct;
37-
use rustc_middle::lint::LintLevelSource;
37+
use rustc_middle::lint::LevelAndSource;
3838
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
3939
use rustc_middle::middle::dependency_format::Dependencies;
4040
use rustc_middle::middle::exported_symbols::SymbolExportKind;
@@ -45,7 +45,6 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
4545
use rustc_session::Session;
4646
use rustc_session::config::{CrateType, OutputFilenames, OutputType, RUST_CGU_EXT};
4747
use rustc_session::cstore::{self, CrateSource};
48-
use rustc_session::lint::Level;
4948
use rustc_session::lint::builtin::LINKER_MESSAGES;
5049
use rustc_session::utils::NativeLibKind;
5150
use rustc_span::Symbol;
@@ -341,7 +340,7 @@ impl CodegenResults {
341340
/// Instead, encode exactly the information we need.
342341
#[derive(Copy, Clone, Debug, Encodable, Decodable)]
343342
pub struct CodegenLintLevels {
344-
linker_messages: (Level, LintLevelSource),
343+
linker_messages: LevelAndSource,
345344
}
346345

347346
impl CodegenLintLevels {

compiler/rustc_const_eval/src/const_eval/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
546546
rustc_session::lint::builtin::LONG_RUNNING_CONST_EVAL,
547547
hir_id,
548548
)
549-
.0
549+
.level
550550
.is_error();
551551
let span = ecx.cur_span();
552552
ecx.tcx.emit_node_span_lint(

compiler/rustc_driver_impl/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ fn print_crate_info(
715715
// lint is unstable and feature gate isn't active, don't print
716716
continue;
717717
}
718-
let level = lint_levels.lint_level(lint).0;
718+
let level = lint_levels.lint_level(lint).level;
719719
println_info!("{}={}", lint.name_lower(), level.as_str());
720720
}
721721
}

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ fn annotation_level_for_level(level: Level) -> annotate_snippets::Level {
9191
Level::Bug | Level::Fatal | Level::Error | Level::DelayedBug => {
9292
annotate_snippets::Level::Error
9393
}
94-
Level::ForceWarning(_) | Level::Warning => annotate_snippets::Level::Warning,
94+
Level::ForceWarning | Level::Warning => annotate_snippets::Level::Warning,
9595
Level::Note | Level::OnceNote => annotate_snippets::Level::Note,
9696
Level::Help | Level::OnceHelp => annotate_snippets::Level::Help,
9797
// FIXME(#59346): Not sure how to map this level
9898
Level::FailureNote => annotate_snippets::Level::Error,
9999
Level::Allow => panic!("Should not call with Allow"),
100-
Level::Expect(_) => panic!("Should not call with Expect"),
100+
Level::Expect => panic!("Should not call with Expect"),
101101
}
102102
}
103103

0 commit comments

Comments
 (0)