Skip to content

Commit ee0838f

Browse files
committed
reword default binding mode notes
(cherry picked from commit a5cc4cb)
1 parent 215bfdd commit ee0838f

File tree

3 files changed

+55
-61
lines changed

3 files changed

+55
-61
lines changed

compiler/rustc_mir_build/src/errors.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,15 +1119,9 @@ impl Subdiagnostic for Rust2024IncompatiblePatSugg {
11191119
for (span, def_br_mutbl) in self.default_mode_labels.into_iter().rev() {
11201120
// Don't point to a macro call site.
11211121
if !span.from_expansion() {
1122-
let dbm_str = match def_br_mutbl {
1123-
ty::Mutability::Not => "ref",
1124-
ty::Mutability::Mut => "ref mut",
1125-
};
1126-
let note_msg = format!(
1127-
"the default binding mode changed to `{dbm_str}` because this has type `{}_`",
1128-
def_br_mutbl.ref_prefix_str()
1129-
);
1130-
let label_msg = format!("the default binding mode is `{dbm_str}`, introduced here");
1122+
let note_msg = "matching on a reference type with a non-reference pattern changes the default binding mode";
1123+
let label_msg =
1124+
format!("this matches on type `{}_`", def_br_mutbl.ref_prefix_str());
11311125
let mut label = MultiSpan::from(span);
11321126
label.push_span_label(span, label_msg);
11331127
diag.span_note(label, note_msg);

tests/ui/pattern/rfc-3627-match-ergonomics-2024/migration_lint.stderr

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ LL | let Foo(mut x) = &Foo(0);
66
|
77
= warning: this changes meaning in Rust 2024
88
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
9-
note: the default binding mode changed to `ref` because this has type `&_`
9+
note: matching on a reference type with a non-reference pattern changes the default binding mode
1010
--> $DIR/migration_lint.rs:25:9
1111
|
1212
LL | let Foo(mut x) = &Foo(0);
13-
| ^^^^^^^^^^ the default binding mode is `ref`, introduced here
13+
| ^^^^^^^^^^ this matches on type `&_`
1414
note: the lint level is defined here
1515
--> $DIR/migration_lint.rs:7:9
1616
|
@@ -29,11 +29,11 @@ LL | let Foo(mut x) = &mut Foo(0);
2929
|
3030
= warning: this changes meaning in Rust 2024
3131
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
32-
note: the default binding mode changed to `ref mut` because this has type `&mut _`
32+
note: matching on a reference type with a non-reference pattern changes the default binding mode
3333
--> $DIR/migration_lint.rs:30:9
3434
|
3535
LL | let Foo(mut x) = &mut Foo(0);
36-
| ^^^^^^^^^^ the default binding mode is `ref mut`, introduced here
36+
| ^^^^^^^^^^ this matches on type `&mut _`
3737
help: make the implied reference pattern explicit
3838
|
3939
LL | let &mut Foo(mut x) = &mut Foo(0);
@@ -47,11 +47,11 @@ LL | let Foo(ref x) = &Foo(0);
4747
|
4848
= warning: this changes meaning in Rust 2024
4949
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
50-
note: the default binding mode changed to `ref` because this has type `&_`
50+
note: matching on a reference type with a non-reference pattern changes the default binding mode
5151
--> $DIR/migration_lint.rs:35:9
5252
|
5353
LL | let Foo(ref x) = &Foo(0);
54-
| ^^^^^^^^^^ the default binding mode is `ref`, introduced here
54+
| ^^^^^^^^^^ this matches on type `&_`
5555
help: make the implied reference pattern explicit
5656
|
5757
LL | let &Foo(ref x) = &Foo(0);
@@ -65,11 +65,11 @@ LL | let Foo(ref x) = &mut Foo(0);
6565
|
6666
= warning: this changes meaning in Rust 2024
6767
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
68-
note: the default binding mode changed to `ref mut` because this has type `&mut _`
68+
note: matching on a reference type with a non-reference pattern changes the default binding mode
6969
--> $DIR/migration_lint.rs:40:9
7070
|
7171
LL | let Foo(ref x) = &mut Foo(0);
72-
| ^^^^^^^^^^ the default binding mode is `ref mut`, introduced here
72+
| ^^^^^^^^^^ this matches on type `&mut _`
7373
help: make the implied reference pattern explicit
7474
|
7575
LL | let &mut Foo(ref x) = &mut Foo(0);
@@ -83,11 +83,11 @@ LL | let Foo(&x) = &Foo(&0);
8383
|
8484
= warning: this changes meaning in Rust 2024
8585
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
86-
note: the default binding mode changed to `ref` because this has type `&_`
86+
note: matching on a reference type with a non-reference pattern changes the default binding mode
8787
--> $DIR/migration_lint.rs:57:9
8888
|
8989
LL | let Foo(&x) = &Foo(&0);
90-
| ^^^^^^^ the default binding mode is `ref`, introduced here
90+
| ^^^^^^^ this matches on type `&_`
9191
help: make the implied reference pattern explicit
9292
|
9393
LL | let &Foo(&x) = &Foo(&0);
@@ -101,11 +101,11 @@ LL | let Foo(&mut x) = &Foo(&mut 0);
101101
|
102102
= warning: this changes meaning in Rust 2024
103103
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
104-
note: the default binding mode changed to `ref` because this has type `&_`
104+
note: matching on a reference type with a non-reference pattern changes the default binding mode
105105
--> $DIR/migration_lint.rs:62:9
106106
|
107107
LL | let Foo(&mut x) = &Foo(&mut 0);
108-
| ^^^^^^^^^^^ the default binding mode is `ref`, introduced here
108+
| ^^^^^^^^^^^ this matches on type `&_`
109109
help: make the implied reference pattern explicit
110110
|
111111
LL | let &Foo(&mut x) = &Foo(&mut 0);
@@ -119,11 +119,11 @@ LL | let Foo(&x) = &mut Foo(&0);
119119
|
120120
= warning: this changes meaning in Rust 2024
121121
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
122-
note: the default binding mode changed to `ref mut` because this has type `&mut _`
122+
note: matching on a reference type with a non-reference pattern changes the default binding mode
123123
--> $DIR/migration_lint.rs:67:9
124124
|
125125
LL | let Foo(&x) = &mut Foo(&0);
126-
| ^^^^^^^ the default binding mode is `ref mut`, introduced here
126+
| ^^^^^^^ this matches on type `&mut _`
127127
help: make the implied reference pattern explicit
128128
|
129129
LL | let &mut Foo(&x) = &mut Foo(&0);
@@ -137,11 +137,11 @@ LL | let Foo(&mut x) = &mut Foo(&mut 0);
137137
|
138138
= warning: this changes meaning in Rust 2024
139139
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
140-
note: the default binding mode changed to `ref mut` because this has type `&mut _`
140+
note: matching on a reference type with a non-reference pattern changes the default binding mode
141141
--> $DIR/migration_lint.rs:72:9
142142
|
143143
LL | let Foo(&mut x) = &mut Foo(&mut 0);
144-
| ^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here
144+
| ^^^^^^^^^^^ this matches on type `&mut _`
145145
help: make the implied reference pattern explicit
146146
|
147147
LL | let &mut Foo(&mut x) = &mut Foo(&mut 0);
@@ -155,11 +155,11 @@ LL | if let Some(&x) = &&&&&Some(&0u8) {
155155
|
156156
= warning: this changes meaning in Rust 2024
157157
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
158-
note: the default binding mode changed to `ref` because this has type `&_`
158+
note: matching on a reference type with a non-reference pattern changes the default binding mode
159159
--> $DIR/migration_lint.rs:81:12
160160
|
161161
LL | if let Some(&x) = &&&&&Some(&0u8) {
162-
| ^^^^^^^^ the default binding mode is `ref`, introduced here
162+
| ^^^^^^^^ this matches on type `&_`
163163
help: make the implied reference patterns explicit
164164
|
165165
LL | if let &&&&&Some(&x) = &&&&&Some(&0u8) {
@@ -173,11 +173,11 @@ LL | if let Some(&mut x) = &&&&&Some(&mut 0u8) {
173173
|
174174
= warning: this changes meaning in Rust 2024
175175
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
176-
note: the default binding mode changed to `ref` because this has type `&_`
176+
note: matching on a reference type with a non-reference pattern changes the default binding mode
177177
--> $DIR/migration_lint.rs:87:12
178178
|
179179
LL | if let Some(&mut x) = &&&&&Some(&mut 0u8) {
180-
| ^^^^^^^^^^^^ the default binding mode is `ref`, introduced here
180+
| ^^^^^^^^^^^^ this matches on type `&_`
181181
help: make the implied reference patterns explicit
182182
|
183183
LL | if let &&&&&Some(&mut x) = &&&&&Some(&mut 0u8) {
@@ -191,11 +191,11 @@ LL | if let Some(&x) = &&&&&mut Some(&0u8) {
191191
|
192192
= warning: this changes meaning in Rust 2024
193193
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
194-
note: the default binding mode changed to `ref` because this has type `&_`
194+
note: matching on a reference type with a non-reference pattern changes the default binding mode
195195
--> $DIR/migration_lint.rs:93:12
196196
|
197197
LL | if let Some(&x) = &&&&&mut Some(&0u8) {
198-
| ^^^^^^^^ the default binding mode is `ref`, introduced here
198+
| ^^^^^^^^ this matches on type `&_`
199199
help: make the implied reference patterns explicit
200200
|
201201
LL | if let &&&&&mut Some(&x) = &&&&&mut Some(&0u8) {
@@ -209,11 +209,11 @@ LL | if let Some(&mut Some(Some(x))) = &mut Some(&mut Some(&mut Some(0u8)))
209209
|
210210
= warning: this changes meaning in Rust 2024
211211
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
212-
note: the default binding mode changed to `ref mut` because this has type `&mut _`
212+
note: matching on a reference type with a non-reference pattern changes the default binding mode
213213
--> $DIR/migration_lint.rs:99:12
214214
|
215215
LL | if let Some(&mut Some(Some(x))) = &mut Some(&mut Some(&mut Some(0u8))) {
216-
| ^^^^^^^^^^^^^^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here
216+
| ^^^^^^^^^^^^^^^^^^^^^^^^ this matches on type `&mut _`
217217
help: make the implied reference patterns and variable binding mode explicit
218218
|
219219
LL | if let &mut Some(&mut Some(&mut Some(ref mut x))) = &mut Some(&mut Some(&mut Some(0u8))) {
@@ -227,11 +227,11 @@ LL | let Struct { a, mut b, c } = &Struct { a: 0, b: 0, c: 0 };
227227
|
228228
= warning: this changes meaning in Rust 2024
229229
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
230-
note: the default binding mode changed to `ref` because this has type `&_`
230+
note: matching on a reference type with a non-reference pattern changes the default binding mode
231231
--> $DIR/migration_lint.rs:111:9
232232
|
233233
LL | let Struct { a, mut b, c } = &Struct { a: 0, b: 0, c: 0 };
234-
| ^^^^^^^^^^^^^^^^^^^^^^ the default binding mode is `ref`, introduced here
234+
| ^^^^^^^^^^^^^^^^^^^^^^ this matches on type `&_`
235235
help: make the implied reference pattern and variable binding modes explicit
236236
|
237237
LL | let &Struct { ref a, mut b, ref c } = &Struct { a: 0, b: 0, c: 0 };
@@ -247,11 +247,11 @@ LL | let Struct { a: &a, b, ref c } = &Struct { a: &0, b: &0, c: &0 };
247247
|
248248
= warning: this changes meaning in Rust 2024
249249
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
250-
note: the default binding mode changed to `ref` because this has type `&_`
250+
note: matching on a reference type with a non-reference pattern changes the default binding mode
251251
--> $DIR/migration_lint.rs:117:9
252252
|
253253
LL | let Struct { a: &a, b, ref c } = &Struct { a: &0, b: &0, c: &0 };
254-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the default binding mode is `ref`, introduced here
254+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ this matches on type `&_`
255255
help: make the implied reference pattern and variable binding mode explicit
256256
|
257257
LL | let &Struct { a: &a, ref b, ref c } = &Struct { a: &0, b: &0, c: &0 };
@@ -267,11 +267,11 @@ LL | if let Struct { a: &Some(a), b: Some(&b), c: Some(c) } =
267267
|
268268
= warning: this changes meaning in Rust 2024
269269
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
270-
note: the default binding mode changed to `ref` because this has type `&_`
270+
note: matching on a reference type with a non-reference pattern changes the default binding mode
271271
--> $DIR/migration_lint.rs:124:12
272272
|
273273
LL | if let Struct { a: &Some(a), b: Some(&b), c: Some(c) } =
274-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the default binding mode is `ref`, introduced here
274+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this matches on type `&_`
275275
help: make the implied reference patterns and variable binding mode explicit
276276
|
277277
LL | if let &Struct { a: &Some(a), b: &Some(&b), c: &Some(ref c) } =
@@ -286,11 +286,11 @@ LL | (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => {
286286
| binding modifier not allowed under `ref` default binding mode
287287
|
288288
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
289-
note: the default binding mode changed to `ref` because this has type `&_`
289+
note: matching on a reference type with a non-reference pattern changes the default binding mode
290290
--> $DIR/migration_lint.rs:137:9
291291
|
292292
LL | (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => {
293-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the default binding mode is `ref`, introduced here
293+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this matches on type `&_`
294294
= note: this error originates in the macro `migration_lint_macros::mixed_edition_pat` (in Nightly builds, run with -Z macro-backtrace for more info)
295295
help: make the implied reference pattern explicit
296296
|
@@ -307,16 +307,16 @@ LL | let [&mut [ref a]] = &mut [&mut &[0]];
307307
|
308308
= warning: this changes meaning in Rust 2024
309309
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
310-
note: the default binding mode changed to `ref` because this has type `&_`
310+
note: matching on a reference type with a non-reference pattern changes the default binding mode
311311
--> $DIR/migration_lint.rs:145:15
312312
|
313313
LL | let [&mut [ref a]] = &mut [&mut &[0]];
314-
| ^^^^^^^ the default binding mode is `ref`, introduced here
315-
note: the default binding mode changed to `ref mut` because this has type `&mut _`
314+
| ^^^^^^^ this matches on type `&_`
315+
note: matching on a reference type with a non-reference pattern changes the default binding mode
316316
--> $DIR/migration_lint.rs:145:9
317317
|
318318
LL | let [&mut [ref a]] = &mut [&mut &[0]];
319-
| ^^^^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here
319+
| ^^^^^^^^^^^^^^ this matches on type `&mut _`
320320
help: make the implied reference patterns explicit
321321
|
322322
LL | let &mut [&mut &[ref a]] = &mut [&mut &[0]];
@@ -330,11 +330,11 @@ LL | let [&(_)] = &[&0];
330330
|
331331
= warning: this changes meaning in Rust 2024
332332
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
333-
note: the default binding mode changed to `ref` because this has type `&_`
333+
note: matching on a reference type with a non-reference pattern changes the default binding mode
334334
--> $DIR/migration_lint.rs:150:9
335335
|
336336
LL | let [&(_)] = &[&0];
337-
| ^^^^^^ the default binding mode is `ref`, introduced here
337+
| ^^^^^^ this matches on type `&_`
338338
help: make the implied reference pattern explicit
339339
|
340340
LL | let &[&(_)] = &[&0];

0 commit comments

Comments
 (0)