mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-02 10:18:25 +00:00

When encountering a typo in a pattern that gets interpreted as an unused binding, look for unit struct/variant of the same type as the binding: ``` error: unused variable: `Non` --> $DIR/binding-typo-2.rs:36:9 | LL | Non => {} | ^^^ | help: if this is intentional, prefix it with an underscore | LL | _Non => {} | + help: you might have meant to pattern match on the similarly named variant `None` | LL - Non => {} LL + std::prelude::v1::None => {} | ```
33 lines
884 B
Rust
33 lines
884 B
Rust
// Issue #51976
|
|
//@ run-rustfix
|
|
#![allow(unused_variables)] // allowed so we don't get overlapping suggestions
|
|
enum Lol {
|
|
Foo,
|
|
Bar,
|
|
}
|
|
|
|
fn foo(x: (Lol, Lol)) {
|
|
use Lol::*;
|
|
match &x {
|
|
(Foo, Bar) | (Bar, Foo) => {}
|
|
//~^ ERROR: variable `Ban` is not bound in all patterns
|
|
//~| HELP: you might have meant to use the similarly named previously used binding `Bar`
|
|
//~| NOTE: pattern doesn't bind `Ban`
|
|
//~| NOTE: variable not in all patterns
|
|
_ => {}
|
|
}
|
|
match &x {
|
|
(Foo, _) | (Bar, Foo) => {}
|
|
//~^ ERROR: variable `Ban` is not bound in all patterns
|
|
//~| HELP: you might have meant to use the similarly named unit variant `Bar`
|
|
//~| NOTE: pattern doesn't bind `Ban`
|
|
//~| NOTE: variable not in all patterns
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
use Lol::*;
|
|
foo((Foo, Bar));
|
|
}
|