Skip to content

Commit b968622

Browse files
committed
clarify wording of match ergonomics diagnostics
1 parent 3014e79 commit b968622

17 files changed

+438
-440
lines changed

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3145,11 +3145,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31453145
// so, we may want to inspect the span's source callee or macro backtrace.
31463146
"occurs within macro expansion".to_owned()
31473147
} else {
3148-
let dbm_str = match def_br_mutbl {
3149-
Mutability::Not => "ref",
3150-
Mutability::Mut => "ref mut",
3151-
};
3152-
format!("{pat_kind} not allowed under `{dbm_str}` default binding mode")
3148+
format!("explicit {pat_kind} not allowed within elided reference pattern")
31533149
};
31543150
info.primary_labels.push((trimmed_span, primary_label));
31553151
}

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,7 @@ declare_lint! {
15991599
"detects patterns whose meaning will change in Rust 2024",
16001600
@future_incompatible = FutureIncompatibleInfo {
16011601
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
1602-
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>",
1602+
reference: "<https://doc.rust-lang.org/edition-guide/rust-2024/match-ergonomics.html>",
16031603
};
16041604
}
16051605

compiler/rustc_mir_build/messages.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,13 @@ mir_build_pointer_pattern = function pointers and raw pointers not derived from
318318
319319
mir_build_privately_uninhabited = pattern `{$witness_1}` is currently uninhabited, but this variant contains private fields which may become inhabited in the future
320320
321-
mir_build_rust_2024_incompatible_pat = {$bad_modifiers ->
321+
mir_build_rust_2024_incompatible_pat = explicit {$bad_modifiers ->
322322
*[true] binding modifiers{$bad_ref_pats ->
323323
*[true] {" "}and reference patterns
324324
[false] {""}
325325
}
326326
[false] reference patterns
327-
} may only be written when the default binding mode is `move`{$is_hard_error ->
327+
} may not be written within elided reference patterns{$is_hard_error ->
328328
*[true] {""}
329329
[false] {" "}in Rust 2024
330330
}

compiler/rustc_mir_build/src/errors.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,9 +1124,11 @@ impl Subdiagnostic for Rust2024IncompatiblePatSugg {
11241124
for (span, def_br_mutbl) in self.default_mode_labels.into_iter().rev() {
11251125
// Don't point to a macro call site.
11261126
if !span.from_expansion() {
1127-
let note_msg = "matching on a reference type with a non-reference pattern changes the default binding mode";
1128-
let label_msg =
1129-
format!("this matches on type `{}_`", def_br_mutbl.ref_prefix_str());
1127+
let note_msg = "matching on a reference type with a non-reference pattern makes variables within bind by reference";
1128+
let label_msg = format!(
1129+
"this matches on a reference type `{}_`",
1130+
def_br_mutbl.ref_prefix_str()
1131+
);
11301132
let mut label = MultiSpan::from(span);
11311133
label.push_span_label(span, label_msg);
11321134
diag.span_note(label, note_msg);
@@ -1150,7 +1152,7 @@ impl Subdiagnostic for Rust2024IncompatiblePatSugg {
11501152
} else {
11511153
String::new()
11521154
};
1153-
format!("make the implied reference pattern{plural_derefs}{and_modes} explicit")
1155+
format!("make the elided reference pattern{plural_derefs}{and_modes} explicit")
11541156
};
11551157
// FIXME(dianne): for peace of mind, don't risk emitting a 0-part suggestion (that panics!)
11561158
if !self.suggestion.is_empty() {

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/mixed-editions.classic2021.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,20 @@ LL | let [&bind_ref_mut!(x)] = &mut [0];
5959
| |
6060
| help: replace this `&` with `&mut`: `&mut`
6161

62-
error: binding modifiers may only be written when the default binding mode is `move`
62+
error: explicit binding modifiers may not be written within elided reference patterns
6363
--> $DIR/mixed-editions.rs:30:10
6464
|
6565
LL | let [bind_ref!(y)] = &[0];
6666
| ^^^^^^^^^^^^ occurs within macro expansion
6767
|
68-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
69-
note: matching on a reference type with a non-reference pattern changes the default binding mode
68+
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/match-ergonomics.html>
69+
note: matching on a reference type with a non-reference pattern makes variables within bind by reference
7070
--> $DIR/mixed-editions.rs:30:9
7171
|
7272
LL | let [bind_ref!(y)] = &[0];
73-
| ^^^^^^^^^^^^^^ this matches on type `&_`
73+
| ^^^^^^^^^^^^^^ this matches on a reference type `&_`
7474
= note: this error originates in the macro `bind_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
75-
help: make the implied reference pattern explicit
75+
help: make the elided reference pattern explicit
7676
|
7777
LL | let &[bind_ref!(y)] = &[0];
7878
| +

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/mixed-editions.classic2024.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ LL | let [&bind_ref_mut!(x)] = &mut [0];
5858
| |
5959
| help: replace this `&` with `&mut`: `&mut`
6060

61-
error: binding modifiers may only be written when the default binding mode is `move`
61+
error: explicit binding modifiers may not be written within elided reference patterns
6262
--> $DIR/mixed-editions.rs:26:21
6363
|
6464
LL | let match_ctor!(ref x) = &[0];
65-
| ^^^ binding modifier not allowed under `ref` default binding mode
65+
| ^^^ explicit binding modifier not allowed within elided reference pattern
6666
|
67-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
68-
help: make the implied reference pattern explicit
67+
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/match-ergonomics.html>
68+
help: make the elided reference pattern explicit
6969
--> $DIR/auxiliary/mixed-editions-macros.rs:11:9
7070
|
7171
LL | &[$p]

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/mixed-editions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ fn assert_type_eq<T, U: Eq<T>>(_: T, _: U) {}
2424
/// only when the binding is from edition 2024.
2525
fn ref_binding_tests() {
2626
let match_ctor!(ref x) = &[0];
27-
//[classic2024,structural2024]~^ ERROR: binding modifiers may only be written when the default binding mode is `move`
27+
//[classic2024,structural2024]~^ ERROR: explicit binding modifiers may not be written within elided reference patterns
2828
#[cfg(any(classic2021, structural2021))] assert_type_eq(x, &0u32);
2929

3030
let [bind_ref!(y)] = &[0];
31-
//[classic2021,structural2021]~^ ERROR: binding modifiers may only be written when the default binding mode is `move`
31+
//[classic2021,structural2021]~^ ERROR: explicit binding modifiers may not be written within elided reference patterns
3232
#[cfg(any(classic2024, structural2024))] assert_type_eq(y, &0u32);
3333
}
3434

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/mixed-editions.structural2021.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@ LL | let [&bind_ref_mut!(x)] = &mut [0];
3737
| |
3838
| help: replace this `&` with `&mut`: `&mut`
3939

40-
error: binding modifiers may only be written when the default binding mode is `move`
40+
error: explicit binding modifiers may not be written within elided reference patterns
4141
--> $DIR/mixed-editions.rs:30:10
4242
|
4343
LL | let [bind_ref!(y)] = &[0];
4444
| ^^^^^^^^^^^^ occurs within macro expansion
4545
|
46-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
47-
note: matching on a reference type with a non-reference pattern changes the default binding mode
46+
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/match-ergonomics.html>
47+
note: matching on a reference type with a non-reference pattern makes variables within bind by reference
4848
--> $DIR/mixed-editions.rs:30:9
4949
|
5050
LL | let [bind_ref!(y)] = &[0];
51-
| ^^^^^^^^^^^^^^ this matches on type `&_`
51+
| ^^^^^^^^^^^^^^ this matches on a reference type `&_`
5252
= note: this error originates in the macro `bind_ref` (in Nightly builds, run with -Z macro-backtrace for more info)
53-
help: make the implied reference pattern explicit
53+
help: make the elided reference pattern explicit
5454
|
5555
LL | let &[bind_ref!(y)] = &[0];
5656
| +

tests/ui/pattern/rfc-3627-match-ergonomics-2024/experimental/mixed-editions.structural2024.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ LL | let [&bind_ref_mut!(x)] = &mut [0];
3636
| |
3737
| help: replace this `&` with `&mut`: `&mut`
3838

39-
error: binding modifiers may only be written when the default binding mode is `move`
39+
error: explicit binding modifiers may not be written within elided reference patterns
4040
--> $DIR/mixed-editions.rs:26:21
4141
|
4242
LL | let match_ctor!(ref x) = &[0];
43-
| ^^^ binding modifier not allowed under `ref` default binding mode
43+
| ^^^ explicit binding modifier not allowed within elided reference pattern
4444
|
45-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
46-
help: make the implied reference pattern explicit
45+
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/match-ergonomics.html>
46+
help: make the elided reference pattern explicit
4747
--> $DIR/auxiliary/mixed-editions-macros.rs:11:9
4848
|
4949
LL | &[$p]

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ LL - let [&mut ref x] = &[&mut 0];
1111
LL + let [&ref x] = &[&mut 0];
1212
|
1313

14-
error: binding modifiers may only be written when the default binding mode is `move`
14+
error: explicit binding modifiers may not be written within elided reference patterns
1515
--> $DIR/ref-binding-on-inh-ref-errors.rs:73:10
1616
|
1717
LL | let [ref mut x] = &[0];
18-
| ^^^^^^^ binding modifier not allowed under `ref` default binding mode
18+
| ^^^^^^^ explicit binding modifier not allowed within elided reference pattern
1919
|
20-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
21-
note: matching on a reference type with a non-reference pattern changes the default binding mode
20+
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/match-ergonomics.html>
21+
note: matching on a reference type with a non-reference pattern makes variables within bind by reference
2222
--> $DIR/ref-binding-on-inh-ref-errors.rs:73:9
2323
|
2424
LL | let [ref mut x] = &[0];
25-
| ^^^^^^^^^^^ this matches on type `&_`
26-
help: make the implied reference pattern explicit
25+
| ^^^^^^^^^^^ this matches on a reference type `&_`
26+
help: make the elided reference pattern explicit
2727
|
2828
LL | let &[ref mut x] = &[0];
2929
| +
@@ -34,53 +34,53 @@ error[E0596]: cannot borrow data in a `&` reference as mutable
3434
LL | let [ref mut x] = &[0];
3535
| ^^^^^^^^^ cannot borrow as mutable
3636

37-
error: binding modifiers may only be written when the default binding mode is `move`
37+
error: explicit binding modifiers may not be written within elided reference patterns
3838
--> $DIR/ref-binding-on-inh-ref-errors.rs:81:10
3939
|
4040
LL | let [ref x] = &[0];
41-
| ^^^ binding modifier not allowed under `ref` default binding mode
41+
| ^^^ explicit binding modifier not allowed within elided reference pattern
4242
|
43-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
44-
note: matching on a reference type with a non-reference pattern changes the default binding mode
43+
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/match-ergonomics.html>
44+
note: matching on a reference type with a non-reference pattern makes variables within bind by reference
4545
--> $DIR/ref-binding-on-inh-ref-errors.rs:81:9
4646
|
4747
LL | let [ref x] = &[0];
48-
| ^^^^^^^ this matches on type `&_`
49-
help: make the implied reference pattern explicit
48+
| ^^^^^^^ this matches on a reference type `&_`
49+
help: make the elided reference pattern explicit
5050
|
5151
LL | let &[ref x] = &[0];
5252
| +
5353

54-
error: binding modifiers may only be written when the default binding mode is `move`
54+
error: explicit binding modifiers may not be written within elided reference patterns
5555
--> $DIR/ref-binding-on-inh-ref-errors.rs:85:10
5656
|
5757
LL | let [ref x] = &mut [0];
58-
| ^^^ binding modifier not allowed under `ref mut` default binding mode
58+
| ^^^ explicit binding modifier not allowed within elided reference pattern
5959
|
60-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
61-
note: matching on a reference type with a non-reference pattern changes the default binding mode
60+
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/match-ergonomics.html>
61+
note: matching on a reference type with a non-reference pattern makes variables within bind by reference
6262
--> $DIR/ref-binding-on-inh-ref-errors.rs:85:9
6363
|
6464
LL | let [ref x] = &mut [0];
65-
| ^^^^^^^ this matches on type `&mut _`
66-
help: make the implied reference pattern explicit
65+
| ^^^^^^^ this matches on a reference type `&mut _`
66+
help: make the elided reference pattern explicit
6767
|
6868
LL | let &mut [ref x] = &mut [0];
6969
| ++++
7070

71-
error: binding modifiers may only be written when the default binding mode is `move`
71+
error: explicit binding modifiers may not be written within elided reference patterns
7272
--> $DIR/ref-binding-on-inh-ref-errors.rs:89:10
7373
|
7474
LL | let [ref mut x] = &mut [0];
75-
| ^^^^^^^ binding modifier not allowed under `ref mut` default binding mode
75+
| ^^^^^^^ explicit binding modifier not allowed within elided reference pattern
7676
|
77-
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
78-
note: matching on a reference type with a non-reference pattern changes the default binding mode
77+
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/match-ergonomics.html>
78+
note: matching on a reference type with a non-reference pattern makes variables within bind by reference
7979
--> $DIR/ref-binding-on-inh-ref-errors.rs:89:9
8080
|
8181
LL | let [ref mut x] = &mut [0];
82-
| ^^^^^^^^^^^ this matches on type `&mut _`
83-
help: make the implied reference pattern explicit
82+
| ^^^^^^^^^^^ this matches on a reference type `&mut _`
83+
help: make the elided reference pattern explicit
8484
|
8585
LL | let &mut [ref mut x] = &mut [0];
8686
| ++++

0 commit comments

Comments
 (0)