diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index d0b7c09507fd..0c20a98059c4 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -804,7 +804,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Determine the binding mode... let bm = match user_bind_annot { - BindingMode(ByRef::No, Mutability::Mut) if matches!(def_br, ByRef::Yes(_)) => { + BindingMode(ByRef::No, Mutability::Mut) if let ByRef::Yes(def_br_mutbl) = def_br => { // Only mention the experimental `mut_ref` feature if if we're in edition 2024 and // using other experimental matching features compatible with it. if pat.span.at_least_rust_2024() @@ -828,18 +828,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pat_info.top_info.hir_id, pat, ident.span, + def_br_mutbl, ); BindingMode(ByRef::No, Mutability::Mut) } } BindingMode(ByRef::No, mutbl) => BindingMode(def_br, mutbl), BindingMode(ByRef::Yes(_), _) => { - if matches!(def_br, ByRef::Yes(_)) { + if let ByRef::Yes(def_br_mutbl) = def_br { // `ref`/`ref mut` overrides the binding mode on edition <= 2021 self.add_rust_2024_migration_desugared_pat( pat_info.top_info.hir_id, pat, ident.span, + def_br_mutbl, ); } user_bind_annot @@ -2378,6 +2380,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pat_info.top_info.hir_id, pat, inner.span, + inh_mut, ) } } @@ -2769,6 +2772,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pat_id: HirId, subpat: &'tcx Pat<'tcx>, cutoff_span: Span, + def_br_mutbl: Mutability, ) { // Try to trim the span we're labeling to just the `&` or binding mode that's an issue. // If the subpattern's span is is from an expansion, the emitted label will not be trimmed. @@ -2791,16 +2795,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // NB: This wording assumes the only expansions that can produce problematic reference // patterns and bindings are macros. If a desugaring or AST pass is added that can do // so, we may want to inspect the span's source callee or macro backtrace. - "occurs within macro expansion" + "occurs within macro expansion".to_owned() } else { - if matches!(subpat.kind, PatKind::Binding(_, _, _, _)) { + let pat_kind = if matches!(subpat.kind, PatKind::Binding(_, _, _, _)) { info.bad_modifiers |= true; - "this binding modifier" + "binding modifier" } else { info.bad_ref_pats |= true; - "this reference pattern" - } + "reference pattern" + }; + let dbm_str = match def_br_mutbl { + Mutability::Not => "ref", + Mutability::Mut => "ref mut", + }; + format!("{pat_kind} not allowed under `{dbm_str}` default binding mode") }; - info.primary_labels.push((trimmed_span, primary_label.to_owned())); + info.primary_labels.push((trimmed_span, primary_label)); } } diff --git a/compiler/rustc_mir_build/src/errors.rs b/compiler/rustc_mir_build/src/errors.rs index e37fe8267842..e83901e175d1 100644 --- a/compiler/rustc_mir_build/src/errors.rs +++ b/compiler/rustc_mir_build/src/errors.rs @@ -1123,6 +1123,27 @@ impl Subdiagnostic for Rust2024IncompatiblePatSugg { diag: &mut Diag<'_, G>, _f: &F, ) { + // Format and emit explanatory notes about default binding modes. Reversing the spans' order + // means if we have nested spans, the innermost ones will be visited first. + for (span, def_br_mutbl) in self.default_mode_labels.into_iter().rev() { + // Don't point to a macro call site. + if !span.from_expansion() { + let dbm_str = match def_br_mutbl { + ty::Mutability::Not => "ref", + ty::Mutability::Mut => "ref mut", + }; + let note_msg = format!( + "the default binding mode changed to `{dbm_str}` because this has type `{}_`", + def_br_mutbl.ref_prefix_str() + ); + let label_msg = format!("the default binding mode is `{dbm_str}`, introduced here"); + let mut label = MultiSpan::from(span); + label.push_span_label(span, label_msg); + diag.span_note(label, note_msg); + } + } + + // Format and emit the suggestion. let applicability = if self.suggestion.iter().all(|(span, _)| span.can_be_used_for_suggestions()) { Applicability::MachineApplicable diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index 5edaa748f6a7..f72ce2fe6fbf 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -66,16 +66,6 @@ pub(super) fn pat_from_hir<'a, 'tcx>( for (span, label) in &info.primary_labels { spans.push_span_label(*span, label.clone()); } - for (span, label_mutbl) in &sugg.default_mode_labels { - // Don't point to a macro call site. - if !span.from_expansion() { - let label = match label_mutbl { - Mutability::Not => "default binding mode is `ref`", - Mutability::Mut => "default binding mode is `ref mut`", - }; - spans.push_span_label(*span, label.to_owned()) - } - } // If a relevant span is from at least edition 2024, this is a hard error. let is_hard_error = spans.primary_spans().iter().any(|span| span.at_least_rust_2024()); if is_hard_error { diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.classic2024.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.classic2024.stderr index 3dbdda335667..74e164619fa9 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.classic2024.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.classic2024.stderr @@ -14,12 +14,14 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/ref-binding-on-inh-ref-errors.rs:67:10 | LL | let [ref mut x] = &[0]; - | -^^^^^^^--- - | || - | |this binding modifier - | default binding mode is `ref` + | ^^^^^^^ binding modifier not allowed under `ref` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/ref-binding-on-inh-ref-errors.rs:67:9 + | +LL | let [ref mut x] = &[0]; + | ^^^^^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern explicit | LL | let &[ref mut x] = &[0]; @@ -35,12 +37,14 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/ref-binding-on-inh-ref-errors.rs:75:10 | LL | let [ref x] = &[0]; - | -^^^--- - | || - | |this binding modifier - | default binding mode is `ref` + | ^^^ binding modifier not allowed under `ref` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/ref-binding-on-inh-ref-errors.rs:75:9 + | +LL | let [ref x] = &[0]; + | ^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern explicit | LL | let &[ref x] = &[0]; @@ -50,12 +54,14 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/ref-binding-on-inh-ref-errors.rs:79:10 | LL | let [ref x] = &mut [0]; - | -^^^--- - | || - | |this binding modifier - | default binding mode is `ref mut` + | ^^^ binding modifier not allowed under `ref mut` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref mut` because this has type `&mut _` + --> $DIR/ref-binding-on-inh-ref-errors.rs:79:9 + | +LL | let [ref x] = &mut [0]; + | ^^^^^^^ the default binding mode is `ref mut`, introduced here help: make the implied reference pattern explicit | LL | let &mut [ref x] = &mut [0]; @@ -65,12 +71,14 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/ref-binding-on-inh-ref-errors.rs:83:10 | LL | let [ref mut x] = &mut [0]; - | -^^^^^^^--- - | || - | |this binding modifier - | default binding mode is `ref mut` + | ^^^^^^^ binding modifier not allowed under `ref mut` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref mut` because this has type `&mut _` + --> $DIR/ref-binding-on-inh-ref-errors.rs:83:9 + | +LL | let [ref mut x] = &mut [0]; + | ^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here help: make the implied reference pattern explicit | LL | let &mut [ref mut x] = &mut [0]; diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.structural2024.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.structural2024.stderr index 14e367f7ee07..422c169d7fd1 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.structural2024.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.structural2024.stderr @@ -2,12 +2,14 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/ref-binding-on-inh-ref-errors.rs:15:11 | LL | let [&ref x] = &[&0]; - | --^^^--- - | | | - | | this binding modifier - | default binding mode is `ref` + | ^^^ binding modifier not allowed under `ref` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/ref-binding-on-inh-ref-errors.rs:15:9 + | +LL | let [&ref x] = &[&0]; + | ^^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern explicit | LL | let &[&ref x] = &[&0]; @@ -17,12 +19,14 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/ref-binding-on-inh-ref-errors.rs:20:11 | LL | let [&ref x] = &mut [&0]; - | --^^^--- - | | | - | | this binding modifier - | default binding mode is `ref mut` + | ^^^ binding modifier not allowed under `ref` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref mut` because this has type `&mut _` + --> $DIR/ref-binding-on-inh-ref-errors.rs:20:9 + | +LL | let [&ref x] = &mut [&0]; + | ^^^^^^^^ the default binding mode is `ref mut`, introduced here help: make the implied reference pattern explicit | LL | let &mut [&ref x] = &mut [&0]; @@ -32,12 +36,14 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/ref-binding-on-inh-ref-errors.rs:25:15 | LL | let [&mut ref x] = &mut [&mut 0]; - | ------^^^--- - | | | - | | this binding modifier - | default binding mode is `ref mut` + | ^^^ binding modifier not allowed under `ref mut` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref mut` because this has type `&mut _` + --> $DIR/ref-binding-on-inh-ref-errors.rs:25:9 + | +LL | let [&mut ref x] = &mut [&mut 0]; + | ^^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here help: make the implied reference pattern explicit | LL | let &mut [&mut ref x] = &mut [&mut 0]; @@ -47,12 +53,14 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/ref-binding-on-inh-ref-errors.rs:30:15 | LL | let [&mut ref mut x] = &mut [&mut 0]; - | ------^^^^^^^--- - | | | - | | this binding modifier - | default binding mode is `ref mut` + | ^^^^^^^ binding modifier not allowed under `ref mut` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref mut` because this has type `&mut _` + --> $DIR/ref-binding-on-inh-ref-errors.rs:30:9 + | +LL | let [&mut ref mut x] = &mut [&mut 0]; + | ^^^^^^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here help: make the implied reference pattern explicit | LL | let &mut [&mut ref mut x] = &mut [&mut 0]; @@ -62,12 +70,14 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/ref-binding-on-inh-ref-errors.rs:39:11 | LL | let [&ref x] = &[&mut 0]; - | --^^^--- - | | | - | | this binding modifier - | default binding mode is `ref` + | ^^^ binding modifier not allowed under `ref` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/ref-binding-on-inh-ref-errors.rs:39:9 + | +LL | let [&ref x] = &[&mut 0]; + | ^^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern explicit | LL | let &[&ref x] = &[&mut 0]; @@ -77,12 +87,14 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/ref-binding-on-inh-ref-errors.rs:45:11 | LL | let [&ref x] = &mut [&mut 0]; - | --^^^--- - | | | - | | this binding modifier - | default binding mode is `ref mut` + | ^^^ binding modifier not allowed under `ref` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref mut` because this has type `&mut _` + --> $DIR/ref-binding-on-inh-ref-errors.rs:45:9 + | +LL | let [&ref x] = &mut [&mut 0]; + | ^^^^^^^^ the default binding mode is `ref mut`, introduced here help: make the implied reference pattern explicit | LL | let &mut [&ref x] = &mut [&mut 0]; @@ -92,12 +104,14 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/ref-binding-on-inh-ref-errors.rs:54:15 | LL | let [&mut ref x] = &[&mut 0]; - | ------^^^--- - | | | - | | this binding modifier - | default binding mode is `ref` + | ^^^ binding modifier not allowed under `ref` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/ref-binding-on-inh-ref-errors.rs:54:9 + | +LL | let [&mut ref x] = &[&mut 0]; + | ^^^^^^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern explicit | LL | let &[&mut ref x] = &[&mut 0]; @@ -107,12 +121,14 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/ref-binding-on-inh-ref-errors.rs:67:10 | LL | let [ref mut x] = &[0]; - | -^^^^^^^--- - | || - | |this binding modifier - | default binding mode is `ref` + | ^^^^^^^ binding modifier not allowed under `ref` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/ref-binding-on-inh-ref-errors.rs:67:9 + | +LL | let [ref mut x] = &[0]; + | ^^^^^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern explicit | LL | let &[ref mut x] = &[0]; @@ -128,12 +144,14 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/ref-binding-on-inh-ref-errors.rs:75:10 | LL | let [ref x] = &[0]; - | -^^^--- - | || - | |this binding modifier - | default binding mode is `ref` + | ^^^ binding modifier not allowed under `ref` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/ref-binding-on-inh-ref-errors.rs:75:9 + | +LL | let [ref x] = &[0]; + | ^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern explicit | LL | let &[ref x] = &[0]; @@ -143,12 +161,14 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/ref-binding-on-inh-ref-errors.rs:79:10 | LL | let [ref x] = &mut [0]; - | -^^^--- - | || - | |this binding modifier - | default binding mode is `ref mut` + | ^^^ binding modifier not allowed under `ref mut` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref mut` because this has type `&mut _` + --> $DIR/ref-binding-on-inh-ref-errors.rs:79:9 + | +LL | let [ref x] = &mut [0]; + | ^^^^^^^ the default binding mode is `ref mut`, introduced here help: make the implied reference pattern explicit | LL | let &mut [ref x] = &mut [0]; @@ -158,12 +178,14 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/ref-binding-on-inh-ref-errors.rs:83:10 | LL | let [ref mut x] = &mut [0]; - | -^^^^^^^--- - | || - | |this binding modifier - | default binding mode is `ref mut` + | ^^^^^^^ binding modifier not allowed under `ref mut` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref mut` because this has type `&mut _` + --> $DIR/ref-binding-on-inh-ref-errors.rs:83:9 + | +LL | let [ref mut x] = &mut [0]; + | ^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here help: make the implied reference pattern explicit | LL | let &mut [ref mut x] = &mut [0]; diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr index eaba337f06bb..cfbd260e0e9a 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr @@ -2,13 +2,15 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/migration_lint.rs:25:13 | LL | let Foo(mut x) = &Foo(0); - | ----^^^--- - | | | - | | this binding modifier - | default binding mode is `ref` + | ^^^ binding modifier not allowed under `ref` default binding mode | = warning: this changes meaning in Rust 2024 = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/migration_lint.rs:25:9 + | +LL | let Foo(mut x) = &Foo(0); + | ^^^^^^^^^^ the default binding mode is `ref`, introduced here note: the lint level is defined here --> $DIR/migration_lint.rs:7:9 | @@ -23,13 +25,15 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/migration_lint.rs:30:13 | LL | let Foo(mut x) = &mut Foo(0); - | ----^^^--- - | | | - | | this binding modifier - | default binding mode is `ref mut` + | ^^^ binding modifier not allowed under `ref mut` default binding mode | = warning: this changes meaning in Rust 2024 = note: for more information, see +note: the default binding mode changed to `ref mut` because this has type `&mut _` + --> $DIR/migration_lint.rs:30:9 + | +LL | let Foo(mut x) = &mut Foo(0); + | ^^^^^^^^^^ the default binding mode is `ref mut`, introduced here help: make the implied reference pattern explicit | LL | let &mut Foo(mut x) = &mut Foo(0); @@ -39,13 +43,15 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/migration_lint.rs:35:13 | LL | let Foo(ref x) = &Foo(0); - | ----^^^--- - | | | - | | this binding modifier - | default binding mode is `ref` + | ^^^ binding modifier not allowed under `ref` default binding mode | = warning: this changes meaning in Rust 2024 = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/migration_lint.rs:35:9 + | +LL | let Foo(ref x) = &Foo(0); + | ^^^^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern explicit | LL | let &Foo(ref x) = &Foo(0); @@ -55,13 +61,15 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/migration_lint.rs:40:13 | LL | let Foo(ref x) = &mut Foo(0); - | ----^^^--- - | | | - | | this binding modifier - | default binding mode is `ref mut` + | ^^^ binding modifier not allowed under `ref mut` default binding mode | = warning: this changes meaning in Rust 2024 = note: for more information, see +note: the default binding mode changed to `ref mut` because this has type `&mut _` + --> $DIR/migration_lint.rs:40:9 + | +LL | let Foo(ref x) = &mut Foo(0); + | ^^^^^^^^^^ the default binding mode is `ref mut`, introduced here help: make the implied reference pattern explicit | LL | let &mut Foo(ref x) = &mut Foo(0); @@ -71,13 +79,15 @@ error: reference patterns may only be written when the default binding mode is ` --> $DIR/migration_lint.rs:57:13 | LL | let Foo(&x) = &Foo(&0); - | ----^-- - | | | - | | this reference pattern - | default binding mode is `ref` + | ^ reference pattern not allowed under `ref` default binding mode | = warning: this changes meaning in Rust 2024 = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/migration_lint.rs:57:9 + | +LL | let Foo(&x) = &Foo(&0); + | ^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern explicit | LL | let &Foo(&x) = &Foo(&0); @@ -87,13 +97,15 @@ error: reference patterns may only be written when the default binding mode is ` --> $DIR/migration_lint.rs:62:13 | LL | let Foo(&mut x) = &Foo(&mut 0); - | ----^^^^--- - | | | - | | this reference pattern - | default binding mode is `ref` + | ^^^^ reference pattern not allowed under `ref` default binding mode | = warning: this changes meaning in Rust 2024 = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/migration_lint.rs:62:9 + | +LL | let Foo(&mut x) = &Foo(&mut 0); + | ^^^^^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern explicit | LL | let &Foo(&mut x) = &Foo(&mut 0); @@ -103,13 +115,15 @@ error: reference patterns may only be written when the default binding mode is ` --> $DIR/migration_lint.rs:67:13 | LL | let Foo(&x) = &mut Foo(&0); - | ----^-- - | | | - | | this reference pattern - | default binding mode is `ref mut` + | ^ reference pattern not allowed under `ref mut` default binding mode | = warning: this changes meaning in Rust 2024 = note: for more information, see +note: the default binding mode changed to `ref mut` because this has type `&mut _` + --> $DIR/migration_lint.rs:67:9 + | +LL | let Foo(&x) = &mut Foo(&0); + | ^^^^^^^ the default binding mode is `ref mut`, introduced here help: make the implied reference pattern explicit | LL | let &mut Foo(&x) = &mut Foo(&0); @@ -119,13 +133,15 @@ error: reference patterns may only be written when the default binding mode is ` --> $DIR/migration_lint.rs:72:13 | LL | let Foo(&mut x) = &mut Foo(&mut 0); - | ----^^^^--- - | | | - | | this reference pattern - | default binding mode is `ref mut` + | ^^^^ reference pattern not allowed under `ref mut` default binding mode | = warning: this changes meaning in Rust 2024 = note: for more information, see +note: the default binding mode changed to `ref mut` because this has type `&mut _` + --> $DIR/migration_lint.rs:72:9 + | +LL | let Foo(&mut x) = &mut Foo(&mut 0); + | ^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here help: make the implied reference pattern explicit | LL | let &mut Foo(&mut x) = &mut Foo(&mut 0); @@ -135,13 +151,15 @@ error: reference patterns may only be written when the default binding mode is ` --> $DIR/migration_lint.rs:81:17 | LL | if let Some(&x) = &&&&&Some(&0u8) { - | -----^-- - | | | - | | this reference pattern - | default binding mode is `ref` + | ^ reference pattern not allowed under `ref` default binding mode | = warning: this changes meaning in Rust 2024 = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/migration_lint.rs:81:12 + | +LL | if let Some(&x) = &&&&&Some(&0u8) { + | ^^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference patterns explicit | LL | if let &&&&&Some(&x) = &&&&&Some(&0u8) { @@ -151,13 +169,15 @@ error: reference patterns may only be written when the default binding mode is ` --> $DIR/migration_lint.rs:87:17 | LL | if let Some(&mut x) = &&&&&Some(&mut 0u8) { - | -----^^^^--- - | | | - | | this reference pattern - | default binding mode is `ref` + | ^^^^ reference pattern not allowed under `ref` default binding mode | = warning: this changes meaning in Rust 2024 = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/migration_lint.rs:87:12 + | +LL | if let Some(&mut x) = &&&&&Some(&mut 0u8) { + | ^^^^^^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference patterns explicit | LL | if let &&&&&Some(&mut x) = &&&&&Some(&mut 0u8) { @@ -167,13 +187,15 @@ error: reference patterns may only be written when the default binding mode is ` --> $DIR/migration_lint.rs:93:17 | LL | if let Some(&x) = &&&&&mut Some(&0u8) { - | -----^-- - | | | - | | this reference pattern - | default binding mode is `ref` + | ^ reference pattern not allowed under `ref` default binding mode | = warning: this changes meaning in Rust 2024 = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/migration_lint.rs:93:12 + | +LL | if let Some(&x) = &&&&&mut Some(&0u8) { + | ^^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference patterns explicit | LL | if let &&&&&mut Some(&x) = &&&&&mut Some(&0u8) { @@ -183,13 +205,15 @@ error: reference patterns may only be written when the default binding mode is ` --> $DIR/migration_lint.rs:99:17 | LL | if let Some(&mut Some(Some(x))) = &mut Some(&mut Some(&mut Some(0u8))) { - | -----^^^^--------------- - | | | - | | this reference pattern - | default binding mode is `ref mut` + | ^^^^ reference pattern not allowed under `ref mut` default binding mode | = warning: this changes meaning in Rust 2024 = note: for more information, see +note: the default binding mode changed to `ref mut` because this has type `&mut _` + --> $DIR/migration_lint.rs:99:12 + | +LL | if let Some(&mut Some(Some(x))) = &mut Some(&mut Some(&mut Some(0u8))) { + | ^^^^^^^^^^^^^^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here help: make the implied reference patterns and variable binding mode explicit | LL | if let &mut Some(&mut Some(&mut Some(ref mut x))) = &mut Some(&mut Some(&mut Some(0u8))) { @@ -199,13 +223,15 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/migration_lint.rs:111:21 | LL | let Struct { a, mut b, c } = &Struct { a: 0, b: 0, c: 0 }; - | ------------^^^------- - | | | - | | this binding modifier - | default binding mode is `ref` + | ^^^ binding modifier not allowed under `ref` default binding mode | = warning: this changes meaning in Rust 2024 = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/migration_lint.rs:111:9 + | +LL | let Struct { a, mut b, c } = &Struct { a: 0, b: 0, c: 0 }; + | ^^^^^^^^^^^^^^^^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern and variable binding modes explicit | LL | let &Struct { ref a, mut b, ref c } = &Struct { a: 0, b: 0, c: 0 }; @@ -215,14 +241,17 @@ error: binding modifiers and reference patterns may only be written when the def --> $DIR/migration_lint.rs:117:21 | LL | let Struct { a: &a, b, ref c } = &Struct { a: &0, b: &0, c: &0 }; - | ------------^------^^^---- - | | | | - | | | this binding modifier - | | this reference pattern - | default binding mode is `ref` + | ^ ^^^ binding modifier not allowed under `ref` default binding mode + | | + | reference pattern not allowed under `ref` default binding mode | = warning: this changes meaning in Rust 2024 = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/migration_lint.rs:117:9 + | +LL | let Struct { a: &a, b, ref c } = &Struct { a: &0, b: &0, c: &0 }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern and variable binding mode explicit | LL | let &Struct { a: &a, ref b, ref c } = &Struct { a: &0, b: &0, c: &0 }; @@ -232,14 +261,17 @@ error: reference patterns may only be written when the default binding mode is ` --> $DIR/migration_lint.rs:124:24 | LL | if let Struct { a: &Some(a), b: Some(&b), c: Some(c) } = - | ------------^-----------------^---------------- - | | | | - | | | this reference pattern - | | this reference pattern - | default binding mode is `ref` + | ^ ^ reference pattern not allowed under `ref` default binding mode + | | + | reference pattern not allowed under `ref` default binding mode | = warning: this changes meaning in Rust 2024 = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/migration_lint.rs:124:12 + | +LL | if let Struct { a: &Some(a), b: Some(&b), c: Some(c) } = + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference patterns and variable binding mode explicit | LL | if let &Struct { a: &Some(a), b: &Some(&b), c: &Some(ref c) } = @@ -249,13 +281,16 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/migration_lint.rs:137:15 | LL | (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => { - | ------^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - | | | | - | | | occurs within macro expansion - | | this binding modifier - | default binding mode is `ref` + | ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ occurs within macro expansion + | | + | binding modifier not allowed under `ref` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/migration_lint.rs:137:9 + | +LL | (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the default binding mode is `ref`, introduced here = note: this error originates in the macro `migration_lint_macros::mixed_edition_pat` (in Nightly builds, run with -Z macro-backtrace for more info) help: make the implied reference pattern explicit | @@ -266,15 +301,22 @@ error: binding modifiers and reference patterns may only be written when the def --> $DIR/migration_lint.rs:145:10 | LL | let [&mut [ref a]] = &mut [&mut &[0]]; - | -^^^^--^^^---- - | || || - | || |this binding modifier - | || default binding mode is `ref` - | |this reference pattern - | default binding mode is `ref mut` + | ^^^^ ^^^ binding modifier not allowed under `ref` default binding mode + | | + | reference pattern not allowed under `ref mut` default binding mode | = warning: this changes meaning in Rust 2024 = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/migration_lint.rs:145:15 + | +LL | let [&mut [ref a]] = &mut [&mut &[0]]; + | ^^^^^^^ the default binding mode is `ref`, introduced here +note: the default binding mode changed to `ref mut` because this has type `&mut _` + --> $DIR/migration_lint.rs:145:9 + | +LL | let [&mut [ref a]] = &mut [&mut &[0]]; + | ^^^^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here help: make the implied reference patterns explicit | LL | let &mut [&mut &[ref a]] = &mut [&mut &[0]]; @@ -284,13 +326,15 @@ error: reference patterns may only be written when the default binding mode is ` --> $DIR/migration_lint.rs:150:10 | LL | let [&(_)] = &[&0]; - | -^---- - | || - | |this reference pattern - | default binding mode is `ref` + | ^ reference pattern not allowed under `ref` default binding mode | = warning: this changes meaning in Rust 2024 = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/migration_lint.rs:150:9 + | +LL | let [&(_)] = &[&0]; + | ^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern explicit | LL | let &[&(_)] = &[&0]; diff --git a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr index ca1749074c19..1d13723370e7 100644 --- a/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr +++ b/tests/ui/pattern/rfc-3627-match-ergonomics-2024/min_match_ergonomics_fail.stderr @@ -103,12 +103,14 @@ error: reference patterns may only be written when the default binding mode is ` --> $DIR/min_match_ergonomics_fail.rs:24:20 | LL | test_pat_on_type![(&x,): &(&T,)]; - | -^--- - | || - | |this reference pattern - | default binding mode is `ref` + | ^ reference pattern not allowed under `ref` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/min_match_ergonomics_fail.rs:24:19 + | +LL | test_pat_on_type![(&x,): &(&T,)]; + | ^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern explicit | LL | test_pat_on_type![&(&x,): &(&T,)]; @@ -118,12 +120,14 @@ error: reference patterns may only be written when the default binding mode is ` --> $DIR/min_match_ergonomics_fail.rs:27:20 | LL | test_pat_on_type![(&mut x,): &(&mut T,)]; - | -^^^^---- - | || - | |this reference pattern - | default binding mode is `ref` + | ^^^^ reference pattern not allowed under `ref` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/min_match_ergonomics_fail.rs:27:19 + | +LL | test_pat_on_type![(&mut x,): &(&mut T,)]; + | ^^^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern explicit | LL | test_pat_on_type![&(&mut x,): &(&mut T,)]; @@ -133,12 +137,14 @@ error: reference patterns may only be written when the default binding mode is ` --> $DIR/min_match_ergonomics_fail.rs:31:28 | LL | test_pat_on_type![Foo { f: &(x,) }: &Foo]; - | ---------^------ - | | | - | | this reference pattern - | default binding mode is `ref` + | ^ reference pattern not allowed under `ref` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/min_match_ergonomics_fail.rs:31:19 + | +LL | test_pat_on_type![Foo { f: &(x,) }: &Foo]; + | ^^^^^^^^^^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern explicit | LL | test_pat_on_type![&Foo { f: &(x,) }: &Foo]; @@ -148,12 +154,14 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/min_match_ergonomics_fail.rs:32:20 | LL | test_pat_on_type![(mut x,): &(T,)]; - | -^^^---- - | || - | |this binding modifier - | default binding mode is `ref` + | ^^^ binding modifier not allowed under `ref` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/min_match_ergonomics_fail.rs:32:19 + | +LL | test_pat_on_type![(mut x,): &(T,)]; + | ^^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern explicit | LL | test_pat_on_type![&(mut x,): &(T,)]; @@ -163,12 +171,14 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/min_match_ergonomics_fail.rs:33:20 | LL | test_pat_on_type![(ref x,): &(T,)]; - | -^^^---- - | || - | |this binding modifier - | default binding mode is `ref` + | ^^^ binding modifier not allowed under `ref` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/min_match_ergonomics_fail.rs:33:19 + | +LL | test_pat_on_type![(ref x,): &(T,)]; + | ^^^^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern explicit | LL | test_pat_on_type![&(ref x,): &(T,)]; @@ -178,12 +188,14 @@ error: binding modifiers may only be written when the default binding mode is `m --> $DIR/min_match_ergonomics_fail.rs:34:20 | LL | test_pat_on_type![(ref mut x,): &mut (T,)]; - | -^^^^^^^---- - | || - | |this binding modifier - | default binding mode is `ref mut` + | ^^^^^^^ binding modifier not allowed under `ref mut` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref mut` because this has type `&mut _` + --> $DIR/min_match_ergonomics_fail.rs:34:19 + | +LL | test_pat_on_type![(ref mut x,): &mut (T,)]; + | ^^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here help: make the implied reference pattern explicit | LL | test_pat_on_type![&mut (ref mut x,): &mut (T,)]; @@ -193,12 +205,14 @@ error: reference patterns may only be written when the default binding mode is ` --> $DIR/min_match_ergonomics_fail.rs:43:10 | LL | (&x,) => x, - | -^--- - | || - | |this reference pattern - | default binding mode is `ref` + | ^ reference pattern not allowed under `ref` default binding mode | = note: for more information, see +note: the default binding mode changed to `ref` because this has type `&_` + --> $DIR/min_match_ergonomics_fail.rs:43:9 + | +LL | (&x,) => x, + | ^^^^^ the default binding mode is `ref`, introduced here help: make the implied reference pattern explicit | LL | &(&x,) => x,