fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1#![warn(clippy::match_ref_pats)] 2#![allow(dead_code, unused_variables)] 3#![allow(clippy::enum_variant_names, clippy::equatable_if_let, clippy::uninlined_format_args)] 4 5fn ref_pats() { 6 { 7 let v = &Some(0); 8 match *v { 9 Some(v) => println!("{:?}", v), 10 None => println!("none"), 11 } 12 match v { 13 // This doesn't trigger; we have a different pattern. 14 &Some(v) => println!("some"), 15 other => println!("other"), 16 } 17 } 18 let tup = &(1, 2); 19 match tup { 20 &(v, 1) => println!("{}", v), 21 _ => println!("none"), 22 } 23 // Special case: using `&` both in expr and pats. 24 let w = Some(0); 25 match w { 26 Some(v) => println!("{:?}", v), 27 None => println!("none"), 28 } 29 // False positive: only wildcard pattern. 30 let w = Some(0); 31 #[allow(clippy::match_single_binding)] 32 match w { 33 _ => println!("none"), 34 } 35 36 let a = &Some(0); 37 if a.is_none() { 38 println!("none"); 39 } 40 41 let b = Some(0); 42 if b.is_none() { 43 println!("none"); 44 } 45} 46 47mod ice_3719 { 48 macro_rules! foo_variant( 49 ($idx:expr) => (Foo::get($idx).unwrap()) 50 ); 51 52 enum Foo { 53 A, 54 B, 55 } 56 57 impl Foo { 58 fn get(idx: u8) -> Option<&'static Self> { 59 match idx { 60 0 => Some(&Foo::A), 61 1 => Some(&Foo::B), 62 _ => None, 63 } 64 } 65 } 66 67 fn ice_3719() { 68 // ICE #3719 69 match foo_variant!(0) { 70 &Foo::A => println!("A"), 71 _ => println!("Wild"), 72 } 73 } 74} 75 76mod issue_7740 { 77 macro_rules! foobar_variant( 78 ($idx:expr) => (FooBar::get($idx).unwrap()) 79 ); 80 81 enum FooBar { 82 Foo, 83 Bar, 84 FooBar, 85 BarFoo, 86 } 87 88 impl FooBar { 89 fn get(idx: u8) -> Option<&'static Self> { 90 match idx { 91 0 => Some(&FooBar::Foo), 92 1 => Some(&FooBar::Bar), 93 2 => Some(&FooBar::FooBar), 94 3 => Some(&FooBar::BarFoo), 95 _ => None, 96 } 97 } 98 } 99 100 fn issue_7740() { 101 // Issue #7740 102 match *foobar_variant!(0) { 103 FooBar::Foo => println!("Foo"), 104 FooBar::Bar => println!("Bar"), 105 FooBar::FooBar => println!("FooBar"), 106 _ => println!("Wild"), 107 } 108 109 // This shouldn't trigger 110 if let &FooBar::BarFoo = foobar_variant!(3) { 111 println!("BarFoo"); 112 } else { 113 println!("Wild"); 114 } 115 } 116} 117 118fn main() {}