Skip to content

Commit a5cc4cb

Browse files
committed
reword default binding mode notes
1 parent 767f820 commit a5cc4cb

File tree

5 files changed

+85
-91
lines changed

5 files changed

+85
-91
lines changed

compiler/rustc_mir_build/src/errors.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1128,15 +1128,9 @@ impl Subdiagnostic for Rust2024IncompatiblePatSugg {
11281128
for (span, def_br_mutbl) in self.default_mode_labels.into_iter().rev() {
11291129
// Don't point to a macro call site.
11301130
if !span.from_expansion() {
1131-
let dbm_str = match def_br_mutbl {
1132-
ty::Mutability::Not => "ref",
1133-
ty::Mutability::Mut => "ref mut",
1134-
};
1135-
let note_msg = format!(
1136-
"the default binding mode changed to `{dbm_str}` because this has type `{}_`",
1137-
def_br_mutbl.ref_prefix_str()
1138-
);
1139-
let label_msg = format!("the default binding mode is `{dbm_str}`, introduced here");
1131+
let note_msg = "matching on a reference type with a non-reference pattern changes the default binding mode";
1132+
let label_msg =
1133+
format!("this matches on type `{}_`", def_br_mutbl.ref_prefix_str());
11401134
let mut label = MultiSpan::from(span);
11411135
label.push_span_label(span, label_msg);
11421136
diag.span_note(label, note_msg);

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.classic2024.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ LL | let [ref mut x] = &[0];
1717
| ^^^^^^^ binding modifier not allowed under `ref` default binding mode
1818
|
1919
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
20-
note: the default binding mode changed to `ref` because this has type `&_`
20+
note: matching on a reference type with a non-reference pattern changes the default binding mode
2121
--> $DIR/ref-binding-on-inh-ref-errors.rs:67:9
2222
|
2323
LL | let [ref mut x] = &[0];
24-
| ^^^^^^^^^^^ the default binding mode is `ref`, introduced here
24+
| ^^^^^^^^^^^ this matches on type `&_`
2525
help: make the implied reference pattern explicit
2626
|
2727
LL | let &[ref mut x] = &[0];
@@ -40,11 +40,11 @@ LL | let [ref x] = &[0];
4040
| ^^^ binding modifier not allowed under `ref` default binding mode
4141
|
4242
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
43-
note: the default binding mode changed to `ref` because this has type `&_`
43+
note: matching on a reference type with a non-reference pattern changes the default binding mode
4444
--> $DIR/ref-binding-on-inh-ref-errors.rs:75:9
4545
|
4646
LL | let [ref x] = &[0];
47-
| ^^^^^^^ the default binding mode is `ref`, introduced here
47+
| ^^^^^^^ this matches on type `&_`
4848
help: make the implied reference pattern explicit
4949
|
5050
LL | let &[ref x] = &[0];
@@ -57,11 +57,11 @@ LL | let [ref x] = &mut [0];
5757
| ^^^ binding modifier not allowed under `ref mut` default binding mode
5858
|
5959
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
60-
note: the default binding mode changed to `ref mut` because this has type `&mut _`
60+
note: matching on a reference type with a non-reference pattern changes the default binding mode
6161
--> $DIR/ref-binding-on-inh-ref-errors.rs:79:9
6262
|
6363
LL | let [ref x] = &mut [0];
64-
| ^^^^^^^ the default binding mode is `ref mut`, introduced here
64+
| ^^^^^^^ this matches on type `&mut _`
6565
help: make the implied reference pattern explicit
6666
|
6767
LL | let &mut [ref x] = &mut [0];
@@ -74,11 +74,11 @@ LL | let [ref mut x] = &mut [0];
7474
| ^^^^^^^ binding modifier not allowed under `ref mut` default binding mode
7575
|
7676
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
77-
note: the default binding mode changed to `ref mut` because this has type `&mut _`
77+
note: matching on a reference type with a non-reference pattern changes the default binding mode
7878
--> $DIR/ref-binding-on-inh-ref-errors.rs:83:9
7979
|
8080
LL | let [ref mut x] = &mut [0];
81-
| ^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here
81+
| ^^^^^^^^^^^ this matches on type `&mut _`
8282
help: make the implied reference pattern explicit
8383
|
8484
LL | let &mut [ref mut x] = &mut [0];

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/ref-binding-on-inh-ref-errors.structural2024.stderr

+22-22
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ LL | let [&ref x] = &[&0];
55
| ^^^ binding modifier not allowed under `ref` default binding mode
66
|
77
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
8-
note: the default binding mode changed to `ref` because this has type `&_`
8+
note: matching on a reference type with a non-reference pattern changes the default binding mode
99
--> $DIR/ref-binding-on-inh-ref-errors.rs:15:9
1010
|
1111
LL | let [&ref x] = &[&0];
12-
| ^^^^^^^^ the default binding mode is `ref`, introduced here
12+
| ^^^^^^^^ this matches on type `&_`
1313
help: make the implied reference pattern explicit
1414
|
1515
LL | let &[&ref x] = &[&0];
@@ -22,11 +22,11 @@ LL | let [&ref x] = &mut [&0];
2222
| ^^^ binding modifier not allowed under `ref` default binding mode
2323
|
2424
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
25-
note: the default binding mode changed to `ref mut` because this has type `&mut _`
25+
note: matching on a reference type with a non-reference pattern changes the default binding mode
2626
--> $DIR/ref-binding-on-inh-ref-errors.rs:20:9
2727
|
2828
LL | let [&ref x] = &mut [&0];
29-
| ^^^^^^^^ the default binding mode is `ref mut`, introduced here
29+
| ^^^^^^^^ this matches on type `&mut _`
3030
help: make the implied reference pattern explicit
3131
|
3232
LL | let &mut [&ref x] = &mut [&0];
@@ -39,11 +39,11 @@ LL | let [&mut ref x] = &mut [&mut 0];
3939
| ^^^ binding modifier not allowed under `ref mut` default binding mode
4040
|
4141
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
42-
note: the default binding mode changed to `ref mut` because this has type `&mut _`
42+
note: matching on a reference type with a non-reference pattern changes the default binding mode
4343
--> $DIR/ref-binding-on-inh-ref-errors.rs:25:9
4444
|
4545
LL | let [&mut ref x] = &mut [&mut 0];
46-
| ^^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here
46+
| ^^^^^^^^^^^^ this matches on type `&mut _`
4747
help: make the implied reference pattern explicit
4848
|
4949
LL | let &mut [&mut ref x] = &mut [&mut 0];
@@ -56,11 +56,11 @@ LL | let [&mut ref mut x] = &mut [&mut 0];
5656
| ^^^^^^^ binding modifier not allowed under `ref mut` default binding mode
5757
|
5858
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
59-
note: the default binding mode changed to `ref mut` because this has type `&mut _`
59+
note: matching on a reference type with a non-reference pattern changes the default binding mode
6060
--> $DIR/ref-binding-on-inh-ref-errors.rs:30:9
6161
|
6262
LL | let [&mut ref mut x] = &mut [&mut 0];
63-
| ^^^^^^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here
63+
| ^^^^^^^^^^^^^^^^ this matches on type `&mut _`
6464
help: make the implied reference pattern explicit
6565
|
6666
LL | let &mut [&mut ref mut x] = &mut [&mut 0];
@@ -73,11 +73,11 @@ LL | let [&ref x] = &[&mut 0];
7373
| ^^^ binding modifier not allowed under `ref` default binding mode
7474
|
7575
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
76-
note: the default binding mode changed to `ref` because this has type `&_`
76+
note: matching on a reference type with a non-reference pattern changes the default binding mode
7777
--> $DIR/ref-binding-on-inh-ref-errors.rs:39:9
7878
|
7979
LL | let [&ref x] = &[&mut 0];
80-
| ^^^^^^^^ the default binding mode is `ref`, introduced here
80+
| ^^^^^^^^ this matches on type `&_`
8181
help: make the implied reference pattern explicit
8282
|
8383
LL | let &[&ref x] = &[&mut 0];
@@ -90,11 +90,11 @@ LL | let [&ref x] = &mut [&mut 0];
9090
| ^^^ binding modifier not allowed under `ref` default binding mode
9191
|
9292
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
93-
note: the default binding mode changed to `ref mut` because this has type `&mut _`
93+
note: matching on a reference type with a non-reference pattern changes the default binding mode
9494
--> $DIR/ref-binding-on-inh-ref-errors.rs:45:9
9595
|
9696
LL | let [&ref x] = &mut [&mut 0];
97-
| ^^^^^^^^ the default binding mode is `ref mut`, introduced here
97+
| ^^^^^^^^ this matches on type `&mut _`
9898
help: make the implied reference pattern explicit
9999
|
100100
LL | let &mut [&ref x] = &mut [&mut 0];
@@ -107,11 +107,11 @@ LL | let [&mut ref x] = &[&mut 0];
107107
| ^^^ binding modifier not allowed under `ref` default binding mode
108108
|
109109
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
110-
note: the default binding mode changed to `ref` because this has type `&_`
110+
note: matching on a reference type with a non-reference pattern changes the default binding mode
111111
--> $DIR/ref-binding-on-inh-ref-errors.rs:54:9
112112
|
113113
LL | let [&mut ref x] = &[&mut 0];
114-
| ^^^^^^^^^^^^ the default binding mode is `ref`, introduced here
114+
| ^^^^^^^^^^^^ this matches on type `&_`
115115
help: make the implied reference pattern explicit
116116
|
117117
LL | let &[&mut ref x] = &[&mut 0];
@@ -124,11 +124,11 @@ LL | let [ref mut x] = &[0];
124124
| ^^^^^^^ binding modifier not allowed under `ref` default binding mode
125125
|
126126
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
127-
note: the default binding mode changed to `ref` because this has type `&_`
127+
note: matching on a reference type with a non-reference pattern changes the default binding mode
128128
--> $DIR/ref-binding-on-inh-ref-errors.rs:67:9
129129
|
130130
LL | let [ref mut x] = &[0];
131-
| ^^^^^^^^^^^ the default binding mode is `ref`, introduced here
131+
| ^^^^^^^^^^^ this matches on type `&_`
132132
help: make the implied reference pattern explicit
133133
|
134134
LL | let &[ref mut x] = &[0];
@@ -147,11 +147,11 @@ LL | let [ref x] = &[0];
147147
| ^^^ binding modifier not allowed under `ref` default binding mode
148148
|
149149
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
150-
note: the default binding mode changed to `ref` because this has type `&_`
150+
note: matching on a reference type with a non-reference pattern changes the default binding mode
151151
--> $DIR/ref-binding-on-inh-ref-errors.rs:75:9
152152
|
153153
LL | let [ref x] = &[0];
154-
| ^^^^^^^ the default binding mode is `ref`, introduced here
154+
| ^^^^^^^ this matches on type `&_`
155155
help: make the implied reference pattern explicit
156156
|
157157
LL | let &[ref x] = &[0];
@@ -164,11 +164,11 @@ LL | let [ref x] = &mut [0];
164164
| ^^^ binding modifier not allowed under `ref mut` default binding mode
165165
|
166166
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
167-
note: the default binding mode changed to `ref mut` because this has type `&mut _`
167+
note: matching on a reference type with a non-reference pattern changes the default binding mode
168168
--> $DIR/ref-binding-on-inh-ref-errors.rs:79:9
169169
|
170170
LL | let [ref x] = &mut [0];
171-
| ^^^^^^^ the default binding mode is `ref mut`, introduced here
171+
| ^^^^^^^ this matches on type `&mut _`
172172
help: make the implied reference pattern explicit
173173
|
174174
LL | let &mut [ref x] = &mut [0];
@@ -181,11 +181,11 @@ LL | let [ref mut x] = &mut [0];
181181
| ^^^^^^^ binding modifier not allowed under `ref mut` default binding mode
182182
|
183183
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
184-
note: the default binding mode changed to `ref mut` because this has type `&mut _`
184+
note: matching on a reference type with a non-reference pattern changes the default binding mode
185185
--> $DIR/ref-binding-on-inh-ref-errors.rs:83:9
186186
|
187187
LL | let [ref mut x] = &mut [0];
188-
| ^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here
188+
| ^^^^^^^^^^^ this matches on type `&mut _`
189189
help: make the implied reference pattern explicit
190190
|
191191
LL | let &mut [ref mut x] = &mut [0];

0 commit comments

Comments
 (0)