- Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing
Description
Summary
With the pattern_type_mismatch
and ref_patterns
lints both enabled, you can get stuck in a situation where you are told:
type of pattern does not match the expression type use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings
If you're using the reproduction code given below, this both options will initially lead to:
cannot move `String` out of reference
You can prefix the internal variables with ref
to fix this, which leads to:
usage of ref pattern consider using `&` for clarity instead
Reproducer
I tried this code:
enum Foo { Bar(String), Baz(String), } impl Foo { fn qux(&self) { match *self { Foo::Bar(ref quux) => println!("{quux}"), Foo::Baz(ref quuux) => println!("{quuux}"), } } }
I expected to see this happen:
No warning, or a config to allow it in this context.
Instead, this happened:
usage of ref pattern consider using `&` for clarity instead
When using &
is not valid in this context.
Version
rustc 1.88.0-nightly (df35ff6c3 2025-04-23) binary: rustc commit-hash: df35ff6c354f1f1fbf430b84e7dea37dfe997f34 commit-date: 2025-04-23 host: x86_64-pc-windows-msvc release: 1.88.0-nightly LLVM version: 20.1.2
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing