You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of #108548 - jamen:master, r=compiler-errors
Clarify the 'use a constant in a pattern' error message
```rs
use std::borrow::Cow;
const ERROR_CODE: Cow<'_, str> = Cow::Borrowed("23505");
fn main() {
let x = Cow::from("23505");
match x {
ERROR_CODE => {}
}
}
```
```
error: to use a constant of type `Cow` in a pattern, `Cow` must be annotated with `#[derive(PartialEq, Eq)]`
--> src/main.rs:9:9
|
9 | ERROR_CODE => {}
| ^^^^^^^^^^
error: could not compile `playground` due to previous error
```
It seems helpful to link to StructuralEq in this message. I was a little confused, because `Cow<'_, str>` implements PartialEq and Eq, but they're not derived, which I learned is necessary for structural equality and using constants in patterns (thanks to the Rust community Discord server)
For tests, should I update every occurrence of this message? I see tests where this is still a warning and I'm not sure if I should update those.
to use a constant of type `{$non_sm_ty}` in a pattern, the constant's initializer must be trivial or `{$non_sm_ty}` must be annotated with `#[derive(PartialEq, Eq)]`
333
333
334
+
mir_build_type_not_structural_tip = the traits must be derived, manual `impl`s are not sufficient
335
+
336
+
mir_build_type_not_structural_more_info = see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
337
+
334
338
mir_build_overlapping_range_endpoints = multiple patterns overlap on their endpoints
335
339
.range = ... with this range
336
340
.note = you likely meant to write mutually exclusive ranges
Copy file name to clipboardexpand all lines: tests/ui/consts/const_in_pattern/warn_corner_cases.stderr
+6
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,8 @@ LL | match None { Some(_) => panic!("whoops"), INDEX => dbg!(INDEX), };
6
6
|
7
7
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8
8
= note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
9
+
= note: the traits must be derived, manual `impl`s are not sufficient
10
+
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
9
11
= note: `#[warn(nontrivial_structural_match)]` on by default
10
12
11
13
warning: to use a constant of type `NoDerive` in a pattern, the constant's initializer must be trivial or `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
18
20
= note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
21
+
= note: the traits must be derived, manual `impl`s are not sufficient
22
+
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
19
23
20
24
warning: to use a constant of type `NoDerive` in a pattern, the constant's initializer must be trivial or `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
0 commit comments