Skip to content

Commit 91108b0

Browse files
committed
make the default binding mode label point to where the & goes
1 parent 767f820 commit 91108b0

File tree

5 files changed

+128
-43
lines changed

5 files changed

+128
-43
lines changed

compiler/rustc_mir_build/src/errors.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1137,8 +1137,11 @@ impl Subdiagnostic for Rust2024IncompatiblePatSugg {
11371137
def_br_mutbl.ref_prefix_str()
11381138
);
11391139
let label_msg = format!("the default binding mode is `{dbm_str}`, introduced here");
1140-
let mut label = MultiSpan::from(span);
1141-
label.push_span_label(span, label_msg);
1140+
// Get a ^---- label with the ^ pointing to where the user would write `&` or `&mut`
1141+
let imaginary_ref_span = span.shrink_to_lo();
1142+
let mut label = MultiSpan::from(imaginary_ref_span);
1143+
label.push_span_label(imaginary_ref_span, label_msg);
1144+
label.push_span_label(span, "");
11421145
diag.span_note(label, note_msg);
11431146
}
11441147
}

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
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+
| ^----------
25+
| |
26+
| the default binding mode is `ref`, introduced here
2527
help: make the implied reference pattern explicit
2628
|
2729
LL | let &[ref mut x] = &[0];
@@ -44,7 +46,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
4446
--> $DIR/ref-binding-on-inh-ref-errors.rs:75:9
4547
|
4648
LL | let [ref x] = &[0];
47-
| ^^^^^^^ the default binding mode is `ref`, introduced here
49+
| ^------
50+
| |
51+
| the default binding mode is `ref`, introduced here
4852
help: make the implied reference pattern explicit
4953
|
5054
LL | let &[ref x] = &[0];
@@ -61,7 +65,9 @@ note: the default binding mode changed to `ref mut` because this has type `&mut
6165
--> $DIR/ref-binding-on-inh-ref-errors.rs:79:9
6266
|
6367
LL | let [ref x] = &mut [0];
64-
| ^^^^^^^ the default binding mode is `ref mut`, introduced here
68+
| ^------
69+
| |
70+
| the default binding mode is `ref mut`, introduced here
6571
help: make the implied reference pattern explicit
6672
|
6773
LL | let &mut [ref x] = &mut [0];
@@ -78,7 +84,9 @@ note: the default binding mode changed to `ref mut` because this has type `&mut
7884
--> $DIR/ref-binding-on-inh-ref-errors.rs:83:9
7985
|
8086
LL | let [ref mut x] = &mut [0];
81-
| ^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here
87+
| ^----------
88+
| |
89+
| the default binding mode is `ref mut`, introduced here
8290
help: make the implied reference pattern explicit
8391
|
8492
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

+33-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
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+
| ^-------
13+
| |
14+
| the default binding mode is `ref`, introduced here
1315
help: make the implied reference pattern explicit
1416
|
1517
LL | let &[&ref x] = &[&0];
@@ -26,7 +28,9 @@ note: the default binding mode changed to `ref mut` because this has type `&mut
2628
--> $DIR/ref-binding-on-inh-ref-errors.rs:20:9
2729
|
2830
LL | let [&ref x] = &mut [&0];
29-
| ^^^^^^^^ the default binding mode is `ref mut`, introduced here
31+
| ^-------
32+
| |
33+
| the default binding mode is `ref mut`, introduced here
3034
help: make the implied reference pattern explicit
3135
|
3236
LL | let &mut [&ref x] = &mut [&0];
@@ -43,7 +47,9 @@ note: the default binding mode changed to `ref mut` because this has type `&mut
4347
--> $DIR/ref-binding-on-inh-ref-errors.rs:25:9
4448
|
4549
LL | let [&mut ref x] = &mut [&mut 0];
46-
| ^^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here
50+
| ^-----------
51+
| |
52+
| the default binding mode is `ref mut`, introduced here
4753
help: make the implied reference pattern explicit
4854
|
4955
LL | let &mut [&mut ref x] = &mut [&mut 0];
@@ -60,7 +66,9 @@ note: the default binding mode changed to `ref mut` because this has type `&mut
6066
--> $DIR/ref-binding-on-inh-ref-errors.rs:30:9
6167
|
6268
LL | let [&mut ref mut x] = &mut [&mut 0];
63-
| ^^^^^^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here
69+
| ^---------------
70+
| |
71+
| the default binding mode is `ref mut`, introduced here
6472
help: make the implied reference pattern explicit
6573
|
6674
LL | let &mut [&mut ref mut x] = &mut [&mut 0];
@@ -77,7 +85,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
7785
--> $DIR/ref-binding-on-inh-ref-errors.rs:39:9
7886
|
7987
LL | let [&ref x] = &[&mut 0];
80-
| ^^^^^^^^ the default binding mode is `ref`, introduced here
88+
| ^-------
89+
| |
90+
| the default binding mode is `ref`, introduced here
8191
help: make the implied reference pattern explicit
8292
|
8393
LL | let &[&ref x] = &[&mut 0];
@@ -94,7 +104,9 @@ note: the default binding mode changed to `ref mut` because this has type `&mut
94104
--> $DIR/ref-binding-on-inh-ref-errors.rs:45:9
95105
|
96106
LL | let [&ref x] = &mut [&mut 0];
97-
| ^^^^^^^^ the default binding mode is `ref mut`, introduced here
107+
| ^-------
108+
| |
109+
| the default binding mode is `ref mut`, introduced here
98110
help: make the implied reference pattern explicit
99111
|
100112
LL | let &mut [&ref x] = &mut [&mut 0];
@@ -111,7 +123,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
111123
--> $DIR/ref-binding-on-inh-ref-errors.rs:54:9
112124
|
113125
LL | let [&mut ref x] = &[&mut 0];
114-
| ^^^^^^^^^^^^ the default binding mode is `ref`, introduced here
126+
| ^-----------
127+
| |
128+
| the default binding mode is `ref`, introduced here
115129
help: make the implied reference pattern explicit
116130
|
117131
LL | let &[&mut ref x] = &[&mut 0];
@@ -128,7 +142,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
128142
--> $DIR/ref-binding-on-inh-ref-errors.rs:67:9
129143
|
130144
LL | let [ref mut x] = &[0];
131-
| ^^^^^^^^^^^ the default binding mode is `ref`, introduced here
145+
| ^----------
146+
| |
147+
| the default binding mode is `ref`, introduced here
132148
help: make the implied reference pattern explicit
133149
|
134150
LL | let &[ref mut x] = &[0];
@@ -151,7 +167,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
151167
--> $DIR/ref-binding-on-inh-ref-errors.rs:75:9
152168
|
153169
LL | let [ref x] = &[0];
154-
| ^^^^^^^ the default binding mode is `ref`, introduced here
170+
| ^------
171+
| |
172+
| the default binding mode is `ref`, introduced here
155173
help: make the implied reference pattern explicit
156174
|
157175
LL | let &[ref x] = &[0];
@@ -168,7 +186,9 @@ note: the default binding mode changed to `ref mut` because this has type `&mut
168186
--> $DIR/ref-binding-on-inh-ref-errors.rs:79:9
169187
|
170188
LL | let [ref x] = &mut [0];
171-
| ^^^^^^^ the default binding mode is `ref mut`, introduced here
189+
| ^------
190+
| |
191+
| the default binding mode is `ref mut`, introduced here
172192
help: make the implied reference pattern explicit
173193
|
174194
LL | let &mut [ref x] = &mut [0];
@@ -185,7 +205,9 @@ note: the default binding mode changed to `ref mut` because this has type `&mut
185205
--> $DIR/ref-binding-on-inh-ref-errors.rs:83:9
186206
|
187207
LL | let [ref mut x] = &mut [0];
188-
| ^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here
208+
| ^----------
209+
| |
210+
| the default binding mode is `ref mut`, introduced here
189211
help: make the implied reference pattern explicit
190212
|
191213
LL | let &mut [ref mut x] = &mut [0];

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

+57-19
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
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+
| ^---------
14+
| |
15+
| the default binding mode is `ref`, introduced here
1416
note: the lint level is defined here
1517
--> $DIR/migration_lint.rs:7:9
1618
|
@@ -33,7 +35,9 @@ note: the default binding mode changed to `ref mut` because this has type `&mut
3335
--> $DIR/migration_lint.rs:30:9
3436
|
3537
LL | let Foo(mut x) = &mut Foo(0);
36-
| ^^^^^^^^^^ the default binding mode is `ref mut`, introduced here
38+
| ^---------
39+
| |
40+
| the default binding mode is `ref mut`, introduced here
3741
help: make the implied reference pattern explicit
3842
|
3943
LL | let &mut Foo(mut x) = &mut Foo(0);
@@ -51,7 +55,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
5155
--> $DIR/migration_lint.rs:35:9
5256
|
5357
LL | let Foo(ref x) = &Foo(0);
54-
| ^^^^^^^^^^ the default binding mode is `ref`, introduced here
58+
| ^---------
59+
| |
60+
| the default binding mode is `ref`, introduced here
5561
help: make the implied reference pattern explicit
5662
|
5763
LL | let &Foo(ref x) = &Foo(0);
@@ -69,7 +75,9 @@ note: the default binding mode changed to `ref mut` because this has type `&mut
6975
--> $DIR/migration_lint.rs:40:9
7076
|
7177
LL | let Foo(ref x) = &mut Foo(0);
72-
| ^^^^^^^^^^ the default binding mode is `ref mut`, introduced here
78+
| ^---------
79+
| |
80+
| the default binding mode is `ref mut`, introduced here
7381
help: make the implied reference pattern explicit
7482
|
7583
LL | let &mut Foo(ref x) = &mut Foo(0);
@@ -87,7 +95,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
8795
--> $DIR/migration_lint.rs:57:9
8896
|
8997
LL | let Foo(&x) = &Foo(&0);
90-
| ^^^^^^^ the default binding mode is `ref`, introduced here
98+
| ^------
99+
| |
100+
| the default binding mode is `ref`, introduced here
91101
help: make the implied reference pattern explicit
92102
|
93103
LL | let &Foo(&x) = &Foo(&0);
@@ -105,7 +115,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
105115
--> $DIR/migration_lint.rs:62:9
106116
|
107117
LL | let Foo(&mut x) = &Foo(&mut 0);
108-
| ^^^^^^^^^^^ the default binding mode is `ref`, introduced here
118+
| ^----------
119+
| |
120+
| the default binding mode is `ref`, introduced here
109121
help: make the implied reference pattern explicit
110122
|
111123
LL | let &Foo(&mut x) = &Foo(&mut 0);
@@ -123,7 +135,9 @@ note: the default binding mode changed to `ref mut` because this has type `&mut
123135
--> $DIR/migration_lint.rs:67:9
124136
|
125137
LL | let Foo(&x) = &mut Foo(&0);
126-
| ^^^^^^^ the default binding mode is `ref mut`, introduced here
138+
| ^------
139+
| |
140+
| the default binding mode is `ref mut`, introduced here
127141
help: make the implied reference pattern explicit
128142
|
129143
LL | let &mut Foo(&x) = &mut Foo(&0);
@@ -141,7 +155,9 @@ note: the default binding mode changed to `ref mut` because this has type `&mut
141155
--> $DIR/migration_lint.rs:72:9
142156
|
143157
LL | let Foo(&mut x) = &mut Foo(&mut 0);
144-
| ^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here
158+
| ^----------
159+
| |
160+
| the default binding mode is `ref mut`, introduced here
145161
help: make the implied reference pattern explicit
146162
|
147163
LL | let &mut Foo(&mut x) = &mut Foo(&mut 0);
@@ -159,7 +175,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
159175
--> $DIR/migration_lint.rs:81:12
160176
|
161177
LL | if let Some(&x) = &&&&&Some(&0u8) {
162-
| ^^^^^^^^ the default binding mode is `ref`, introduced here
178+
| ^-------
179+
| |
180+
| the default binding mode is `ref`, introduced here
163181
help: make the implied reference patterns explicit
164182
|
165183
LL | if let &&&&&Some(&x) = &&&&&Some(&0u8) {
@@ -177,7 +195,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
177195
--> $DIR/migration_lint.rs:87:12
178196
|
179197
LL | if let Some(&mut x) = &&&&&Some(&mut 0u8) {
180-
| ^^^^^^^^^^^^ the default binding mode is `ref`, introduced here
198+
| ^-----------
199+
| |
200+
| the default binding mode is `ref`, introduced here
181201
help: make the implied reference patterns explicit
182202
|
183203
LL | if let &&&&&Some(&mut x) = &&&&&Some(&mut 0u8) {
@@ -195,7 +215,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
195215
--> $DIR/migration_lint.rs:93:12
196216
|
197217
LL | if let Some(&x) = &&&&&mut Some(&0u8) {
198-
| ^^^^^^^^ the default binding mode is `ref`, introduced here
218+
| ^-------
219+
| |
220+
| the default binding mode is `ref`, introduced here
199221
help: make the implied reference patterns explicit
200222
|
201223
LL | if let &&&&&mut Some(&x) = &&&&&mut Some(&0u8) {
@@ -213,7 +235,9 @@ note: the default binding mode changed to `ref mut` because this has type `&mut
213235
--> $DIR/migration_lint.rs:99:12
214236
|
215237
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
238+
| ^-----------------------
239+
| |
240+
| the default binding mode is `ref mut`, introduced here
217241
help: make the implied reference patterns and variable binding mode explicit
218242
|
219243
LL | if let &mut Some(&mut Some(&mut Some(ref mut x))) = &mut Some(&mut Some(&mut Some(0u8))) {
@@ -231,7 +255,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
231255
--> $DIR/migration_lint.rs:111:9
232256
|
233257
LL | let Struct { a, mut b, c } = &Struct { a: 0, b: 0, c: 0 };
234-
| ^^^^^^^^^^^^^^^^^^^^^^ the default binding mode is `ref`, introduced here
258+
| ^---------------------
259+
| |
260+
| the default binding mode is `ref`, introduced here
235261
help: make the implied reference pattern and variable binding modes explicit
236262
|
237263
LL | let &Struct { ref a, mut b, ref c } = &Struct { a: 0, b: 0, c: 0 };
@@ -251,7 +277,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
251277
--> $DIR/migration_lint.rs:117:9
252278
|
253279
LL | let Struct { a: &a, b, ref c } = &Struct { a: &0, b: &0, c: &0 };
254-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the default binding mode is `ref`, introduced here
280+
| ^-------------------------
281+
| |
282+
| the default binding mode is `ref`, introduced here
255283
help: make the implied reference pattern and variable binding mode explicit
256284
|
257285
LL | let &Struct { a: &a, ref b, ref c } = &Struct { a: &0, b: &0, c: &0 };
@@ -271,7 +299,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
271299
--> $DIR/migration_lint.rs:124:12
272300
|
273301
LL | if let Struct { a: &Some(a), b: Some(&b), c: Some(c) } =
274-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the default binding mode is `ref`, introduced here
302+
| ^----------------------------------------------
303+
| |
304+
| the default binding mode is `ref`, introduced here
275305
help: make the implied reference patterns and variable binding mode explicit
276306
|
277307
LL | if let &Struct { a: &Some(a), b: &Some(&b), c: &Some(ref c) } =
@@ -290,7 +320,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
290320
--> $DIR/migration_lint.rs:137:9
291321
|
292322
LL | (Some(mut x), migration_lint_macros::mixed_edition_pat!(y)) => {
293-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the default binding mode is `ref`, introduced here
323+
| ^----------------------------------------------------------
324+
| |
325+
| the default binding mode is `ref`, introduced here
294326
= note: this error originates in the macro `migration_lint_macros::mixed_edition_pat` (in Nightly builds, run with -Z macro-backtrace for more info)
295327
help: make the implied reference pattern explicit
296328
|
@@ -311,12 +343,16 @@ note: the default binding mode changed to `ref` because this has type `&_`
311343
--> $DIR/migration_lint.rs:145:15
312344
|
313345
LL | let [&mut [ref a]] = &mut [&mut &[0]];
314-
| ^^^^^^^ the default binding mode is `ref`, introduced here
346+
| ^------
347+
| |
348+
| the default binding mode is `ref`, introduced here
315349
note: the default binding mode changed to `ref mut` because this has type `&mut _`
316350
--> $DIR/migration_lint.rs:145:9
317351
|
318352
LL | let [&mut [ref a]] = &mut [&mut &[0]];
319-
| ^^^^^^^^^^^^^^ the default binding mode is `ref mut`, introduced here
353+
| ^-------------
354+
| |
355+
| the default binding mode is `ref mut`, introduced here
320356
help: make the implied reference patterns explicit
321357
|
322358
LL | let &mut [&mut &[ref a]] = &mut [&mut &[0]];
@@ -334,7 +370,9 @@ note: the default binding mode changed to `ref` because this has type `&_`
334370
--> $DIR/migration_lint.rs:150:9
335371
|
336372
LL | let [&(_)] = &[&0];
337-
| ^^^^^^ the default binding mode is `ref`, introduced here
373+
| ^-----
374+
| |
375+
| the default binding mode is `ref`, introduced here
338376
help: make the implied reference pattern explicit
339377
|
340378
LL | let &[&(_)] = &[&0];

0 commit comments

Comments
 (0)