Skip to content

Commit

Permalink
reword default binding mode notes
Browse files Browse the repository at this point in the history
  • Loading branch information
dianne committed Feb 5, 2025
1 parent 767f820 commit a5cc4cb
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 91 deletions.
12 changes: 3 additions & 9 deletions compiler/rustc_mir_build/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,15 +1128,9 @@ impl Subdiagnostic for Rust2024IncompatiblePatSugg {
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 note_msg = "matching on a reference type with a non-reference pattern changes the default binding mode";
let label_msg =
format!("this matches on type `{}_`", def_br_mutbl.ref_prefix_str());
let mut label = MultiSpan::from(span);
label.push_span_label(span, label_msg);
diag.span_note(label, note_msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ LL | let [ref mut x] = &[0];
| ^^^^^^^ binding modifier not allowed under `ref` default binding mode
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: the default binding mode changed to `ref` because this has type `&_`
note: matching on a reference type with a non-reference pattern changes the default binding mode
--> $DIR/ref-binding-on-inh-ref-errors.rs:67:9
|
LL | let [ref mut x] = &[0];
| ^^^^^^^^^^^ the default binding mode is `ref`, introduced here
| ^^^^^^^^^^^ this matches on type `&_`
help: make the implied reference pattern explicit
|
LL | let &[ref mut x] = &[0];
Expand All @@ -40,11 +40,11 @@ LL | let [ref x] = &[0];
| ^^^ binding modifier not allowed under `ref` default binding mode
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: the default binding mode changed to `ref` because this has type `&_`
note: matching on a reference type with a non-reference pattern changes the default binding mode
--> $DIR/ref-binding-on-inh-ref-errors.rs:75:9
|
LL | let [ref x] = &[0];
| ^^^^^^^ the default binding mode is `ref`, introduced here
| ^^^^^^^ this matches on type `&_`
help: make the implied reference pattern explicit
|
LL | let &[ref x] = &[0];
Expand All @@ -57,11 +57,11 @@ LL | let [ref x] = &mut [0];
| ^^^ binding modifier not allowed under `ref mut` default binding mode
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: the default binding mode changed to `ref mut` because this has type `&mut _`
note: matching on a reference type with a non-reference pattern changes the default binding mode
--> $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
| ^^^^^^^ this matches on type `&mut _`
help: make the implied reference pattern explicit
|
LL | let &mut [ref x] = &mut [0];
Expand All @@ -74,11 +74,11 @@ LL | let [ref mut x] = &mut [0];
| ^^^^^^^ binding modifier not allowed under `ref mut` default binding mode
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: the default binding mode changed to `ref mut` because this has type `&mut _`
note: matching on a reference type with a non-reference pattern changes the default binding mode
--> $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
| ^^^^^^^^^^^ this matches on type `&mut _`
help: make the implied reference pattern explicit
|
LL | let &mut [ref mut x] = &mut [0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ LL | let [&ref x] = &[&0];
| ^^^ binding modifier not allowed under `ref` default binding mode
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: the default binding mode changed to `ref` because this has type `&_`
note: matching on a reference type with a non-reference pattern changes the default binding mode
--> $DIR/ref-binding-on-inh-ref-errors.rs:15:9
|
LL | let [&ref x] = &[&0];
| ^^^^^^^^ the default binding mode is `ref`, introduced here
| ^^^^^^^^ this matches on type `&_`
help: make the implied reference pattern explicit
|
LL | let &[&ref x] = &[&0];
Expand All @@ -22,11 +22,11 @@ LL | let [&ref x] = &mut [&0];
| ^^^ binding modifier not allowed under `ref` default binding mode
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: the default binding mode changed to `ref mut` because this has type `&mut _`
note: matching on a reference type with a non-reference pattern changes the default binding mode
--> $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
| ^^^^^^^^ this matches on type `&mut _`
help: make the implied reference pattern explicit
|
LL | let &mut [&ref x] = &mut [&0];
Expand All @@ -39,11 +39,11 @@ LL | let [&mut ref x] = &mut [&mut 0];
| ^^^ binding modifier not allowed under `ref mut` default binding mode
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: the default binding mode changed to `ref mut` because this has type `&mut _`
note: matching on a reference type with a non-reference pattern changes the default binding mode
--> $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
| ^^^^^^^^^^^^ this matches on type `&mut _`
help: make the implied reference pattern explicit
|
LL | let &mut [&mut ref x] = &mut [&mut 0];
Expand All @@ -56,11 +56,11 @@ LL | let [&mut ref mut x] = &mut [&mut 0];
| ^^^^^^^ binding modifier not allowed under `ref mut` default binding mode
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: the default binding mode changed to `ref mut` because this has type `&mut _`
note: matching on a reference type with a non-reference pattern changes the default binding mode
--> $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
| ^^^^^^^^^^^^^^^^ this matches on type `&mut _`
help: make the implied reference pattern explicit
|
LL | let &mut [&mut ref mut x] = &mut [&mut 0];
Expand All @@ -73,11 +73,11 @@ LL | let [&ref x] = &[&mut 0];
| ^^^ binding modifier not allowed under `ref` default binding mode
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: the default binding mode changed to `ref` because this has type `&_`
note: matching on a reference type with a non-reference pattern changes the default binding mode
--> $DIR/ref-binding-on-inh-ref-errors.rs:39:9
|
LL | let [&ref x] = &[&mut 0];
| ^^^^^^^^ the default binding mode is `ref`, introduced here
| ^^^^^^^^ this matches on type `&_`
help: make the implied reference pattern explicit
|
LL | let &[&ref x] = &[&mut 0];
Expand All @@ -90,11 +90,11 @@ LL | let [&ref x] = &mut [&mut 0];
| ^^^ binding modifier not allowed under `ref` default binding mode
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: the default binding mode changed to `ref mut` because this has type `&mut _`
note: matching on a reference type with a non-reference pattern changes the default binding mode
--> $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
| ^^^^^^^^ this matches on type `&mut _`
help: make the implied reference pattern explicit
|
LL | let &mut [&ref x] = &mut [&mut 0];
Expand All @@ -107,11 +107,11 @@ LL | let [&mut ref x] = &[&mut 0];
| ^^^ binding modifier not allowed under `ref` default binding mode
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: the default binding mode changed to `ref` because this has type `&_`
note: matching on a reference type with a non-reference pattern changes the default binding mode
--> $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
| ^^^^^^^^^^^^ this matches on type `&_`
help: make the implied reference pattern explicit
|
LL | let &[&mut ref x] = &[&mut 0];
Expand All @@ -124,11 +124,11 @@ LL | let [ref mut x] = &[0];
| ^^^^^^^ binding modifier not allowed under `ref` default binding mode
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: the default binding mode changed to `ref` because this has type `&_`
note: matching on a reference type with a non-reference pattern changes the default binding mode
--> $DIR/ref-binding-on-inh-ref-errors.rs:67:9
|
LL | let [ref mut x] = &[0];
| ^^^^^^^^^^^ the default binding mode is `ref`, introduced here
| ^^^^^^^^^^^ this matches on type `&_`
help: make the implied reference pattern explicit
|
LL | let &[ref mut x] = &[0];
Expand All @@ -147,11 +147,11 @@ LL | let [ref x] = &[0];
| ^^^ binding modifier not allowed under `ref` default binding mode
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: the default binding mode changed to `ref` because this has type `&_`
note: matching on a reference type with a non-reference pattern changes the default binding mode
--> $DIR/ref-binding-on-inh-ref-errors.rs:75:9
|
LL | let [ref x] = &[0];
| ^^^^^^^ the default binding mode is `ref`, introduced here
| ^^^^^^^ this matches on type `&_`
help: make the implied reference pattern explicit
|
LL | let &[ref x] = &[0];
Expand All @@ -164,11 +164,11 @@ LL | let [ref x] = &mut [0];
| ^^^ binding modifier not allowed under `ref mut` default binding mode
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: the default binding mode changed to `ref mut` because this has type `&mut _`
note: matching on a reference type with a non-reference pattern changes the default binding mode
--> $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
| ^^^^^^^ this matches on type `&mut _`
help: make the implied reference pattern explicit
|
LL | let &mut [ref x] = &mut [0];
Expand All @@ -181,11 +181,11 @@ LL | let [ref mut x] = &mut [0];
| ^^^^^^^ binding modifier not allowed under `ref mut` default binding mode
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
note: the default binding mode changed to `ref mut` because this has type `&mut _`
note: matching on a reference type with a non-reference pattern changes the default binding mode
--> $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
| ^^^^^^^^^^^ this matches on type `&mut _`
help: make the implied reference pattern explicit
|
LL | let &mut [ref mut x] = &mut [0];
Expand Down
Loading

0 comments on commit a5cc4cb

Please sign in to comment.