fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1//@aux-build:proc_macros.rs 2#![feature(if_let_guard)] 3#![allow(clippy::no_effect, unused)] 4#![warn(clippy::redundant_guards)] 5 6#[macro_use] 7extern crate proc_macros; 8 9struct A(u32); 10 11struct B { 12 e: Option<A>, 13} 14 15struct C(u32, u32); 16 17#[derive(PartialEq)] 18struct FloatWrapper(f32); 19fn issue11304() { 20 match 0.1 { 21 x if x == 0.0 => todo!(), 22 _ => todo!(), 23 } 24 match FloatWrapper(0.1) { 25 x if x == FloatWrapper(0.0) => todo!(), 26 _ => todo!(), 27 } 28} 29 30fn main() { 31 let c = C(1, 2); 32 match c { 33 C(x, 1) => .., 34 _ => todo!(), 35 }; 36 37 let x = Some(Some(1)); 38 match x { 39 Some(Some(1)) if true => .., 40 Some(Some(1)) => { 41 println!("a"); 42 .. 43 }, 44 Some(Some(1)) => .., 45 Some(Some(2)) => .., 46 Some(Some(2)) => .., 47 // Don't lint, since x is used in the body 48 Some(x) if let Some(1) = x => { 49 x; 50 .. 51 } 52 _ => todo!(), 53 }; 54 let y = 1; 55 match x { 56 // Don't inline these, since y is not from the pat 57 Some(x) if matches!(y, 1 if true) => .., 58 Some(x) if let 1 = y => .., 59 Some(x) if y == 2 => .., 60 Some(x) if 2 == y => .., 61 _ => todo!(), 62 }; 63 let a = A(1); 64 match a { 65 _ if a.0 == 1 => {}, 66 _ if 1 == a.0 => {}, 67 _ => todo!(), 68 } 69 let b = B { e: Some(A(0)) }; 70 match b { 71 B { e: Some(A(2)) } => .., 72 _ => todo!(), 73 }; 74 // Do not lint, since we cannot represent this as a pattern (at least, without a conversion) 75 let v = Some(vec![1u8, 2, 3]); 76 match v { 77 Some(x) if x == [1] => {}, 78 _ => {}, 79 } 80 81 external! { 82 let x = Some(Some(1)); 83 match x { 84 Some(x) if let Some(1) = x => .., 85 _ => todo!(), 86 }; 87 } 88 with_span! { 89 span 90 let x = Some(Some(1)); 91 match x { 92 Some(x) if let Some(1) = x => .., 93 _ => todo!(), 94 }; 95 } 96} 97 98enum E { 99 A(&'static str), 100 B(&'static str), 101 C(&'static str), 102} 103 104fn i() { 105 match E::A("") { 106 // Do not lint 107 E::A(x) | E::B(x) | E::C(x) if x == "from an or pattern" => {}, 108 E::A("not from an or pattern") => {}, 109 _ => {}, 110 }; 111} 112 113fn h(v: Option<u32>) { 114 match v { 115 Some(0) => .., 116 _ => .., 117 }; 118} 119 120// Do not lint 121 122fn f(s: Option<std::ffi::OsString>) { 123 match s { 124 Some(x) if x == "a" => {}, 125 Some(x) if "a" == x => {}, 126 _ => {}, 127 } 128} 129 130struct S { 131 a: usize, 132} 133 134impl PartialEq for S { 135 fn eq(&self, _: &Self) -> bool { 136 true 137 } 138} 139 140impl Eq for S {} 141 142static CONST_S: S = S { a: 1 }; 143 144fn g(opt_s: Option<S>) { 145 match opt_s { 146 Some(x) if x == CONST_S => {}, 147 Some(x) if CONST_S == x => {}, 148 _ => {}, 149 } 150} 151 152mod issue11465 { 153 enum A { 154 Foo([u8; 3]), 155 } 156 157 struct B { 158 b: String, 159 c: i32, 160 } 161 162 fn issue11465() { 163 let c = Some(1); 164 match c { 165 Some(1) => {}, 166 Some(1) => {}, 167 Some(2) => {}, 168 Some(3) => {}, 169 _ => {}, 170 }; 171 172 let enum_a = A::Foo([98, 97, 114]); 173 match enum_a { 174 A::Foo(ref arr) if arr == b"foo" => {}, 175 A::Foo(ref arr) if b"foo" == arr => {}, 176 A::Foo(ref arr) if let b"bar" = arr => {}, 177 A::Foo(ref arr) if matches!(arr, b"baz") => {}, 178 _ => {}, 179 }; 180 181 let struct_b = B { 182 b: "bar".to_string(), 183 c: 42, 184 }; 185 match struct_b { 186 B { ref b, .. } if b == "bar" => {}, 187 B { ref b, .. } if "bar" == b => {}, 188 B { c: 1, .. } => {}, 189 B { c: 1, .. } => {}, 190 B { c: 1, .. } => {}, 191 B { c: 1, .. } => {}, 192 _ => {}, 193 } 194 } 195}