rust/compiler/rustc_mir_build/src
Matthias Krüger a7c07cf731
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.
2023-03-28 07:01:08 +02:00
..
build Bless tidy 2023-03-27 18:58:07 +00:00
thir Refactor: VariantIdx::from_u32(0) -> FIRST_VARIANT 2023-03-25 18:58:25 -07:00
check_unsafety.rs Don't trim path for unsafe_op_in_unsafe_fn lints 2023-01-03 00:28:54 +01:00
errors.rs Add notes to non-structural const in pattern error message 2023-03-27 11:08:11 -04:00
lib.rs Simplify message paths 2023-03-11 22:51:57 +01:00
lints.rs IdentitySubsts::identity_for_item takes Into<DefId> 2023-03-21 15:38:52 +00:00