diff --git a/tests/ui/matches.rs b/tests/ui/matches.rs index a40b80378..c7c84b5d9 100644 --- a/tests/ui/matches.rs +++ b/tests/ui/matches.rs @@ -150,4 +150,29 @@ fn match_as_ref() { }; } -fn main() {} +macro_rules! foo_variant( + ($idx:expr) => (Foo::get($idx).unwrap()) +); + +enum Foo { + A, + B, +} + +impl Foo { + fn get(idx: u8) -> Option<&'static Self> { + match idx { + 0 => Some(&Foo::A), + 1 => Some(&Foo::B), + _ => None, + } + } +} + +fn main() { + // ICE #3719 + match foo_variant!(0) { + &Foo::A => println!("A"), + _ => println!("Wild"), + } +} diff --git a/tests/ui/matches.stderr b/tests/ui/matches.stderr index a3714a69e..b4159f7a6 100644 --- a/tests/ui/matches.stderr +++ b/tests/ui/matches.stderr @@ -278,5 +278,19 @@ LL | | Some(ref mut v) => Some(v), LL | | }; | |_____^ help: try this: `mut_owned.as_mut()` -error: aborting due to 19 previous errors +error: you don't need to add `&` to all patterns + --> $DIR/matches.rs:174:5 + | +LL | / match foo_variant!(0) { +LL | | &Foo::A => println!("A"), +LL | | _ => println!("Wild"), +LL | | } + | |_____^ +help: instead of prefixing all patterns with `&`, you can dereference the expression + | +LL | match *foo_variant!(0) { +LL | Foo::A => println!("A"), + | + +error: aborting due to 20 previous errors