about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-03-28 07:01:08 +0200
committerGitHub <noreply@github.com>2023-03-28 07:01:08 +0200
commita7c07cf7315c8ed74723d0e251ef01847e75a892 (patch)
treef77baa32a483e03b249a07cf149fe6346c083bcc /src/tools
parent5ce70ed8dafeb3029cc7b493570a6f3e1c2f422b (diff)
parent73c34cbaf71b40bd7944b3eb3d64009b93d05873 (diff)
downloadrust-a7c07cf7315c8ed74723d0e251ef01847e75a892.tar.gz
rust-a7c07cf7315c8ed74723d0e251ef01847e75a892.zip
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.
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-6254.stderr2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/crashes/ice-6254.stderr b/src/tools/clippy/tests/ui/crashes/ice-6254.stderr
index 22d82a30c6a..263c27d3d64 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-6254.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-6254.stderr
@@ -6,6 +6,8 @@ LL |         FOO_REF_REF => {},
    |
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
+   = note: the traits must be derived, manual `impl`s are not sufficient
+   = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
    = note: `-D indirect-structural-match` implied by `-D warnings`
 
 error: aborting due to previous error