2023-08-24 14:32:12 -05:00
|
|
|
//@aux-build:proc_macros.rs
|
2023-07-31 16:53:53 -05:00
|
|
|
#![feature(if_let_guard)]
|
|
|
|
#![allow(clippy::no_effect, unused)]
|
|
|
|
#![warn(clippy::redundant_guards)]
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate proc_macros;
|
|
|
|
|
|
|
|
struct A(u32);
|
|
|
|
|
|
|
|
struct B {
|
|
|
|
e: Option<A>,
|
|
|
|
}
|
|
|
|
|
|
|
|
struct C(u32, u32);
|
|
|
|
|
2023-08-11 07:05:13 -05:00
|
|
|
#[derive(PartialEq)]
|
|
|
|
struct FloatWrapper(f32);
|
|
|
|
fn issue11304() {
|
|
|
|
match 0.1 {
|
|
|
|
x if x == 0.0 => todo!(),
|
|
|
|
_ => todo!(),
|
|
|
|
}
|
|
|
|
match FloatWrapper(0.1) {
|
|
|
|
x if x == FloatWrapper(0.0) => todo!(),
|
|
|
|
_ => todo!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-31 16:53:53 -05:00
|
|
|
fn main() {
|
|
|
|
let c = C(1, 2);
|
|
|
|
match c {
|
|
|
|
C(x, 1) => ..,
|
|
|
|
_ => todo!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let x = Some(Some(1));
|
|
|
|
match x {
|
|
|
|
Some(Some(1)) if true => ..,
|
|
|
|
Some(Some(1)) => {
|
|
|
|
println!("a");
|
|
|
|
..
|
|
|
|
},
|
|
|
|
Some(Some(1)) => ..,
|
|
|
|
Some(Some(2)) => ..,
|
|
|
|
// Don't lint, since x is used in the body
|
|
|
|
Some(x) if let Some(1) = x => {
|
|
|
|
x;
|
|
|
|
..
|
|
|
|
}
|
|
|
|
_ => todo!(),
|
|
|
|
};
|
|
|
|
let y = 1;
|
|
|
|
match x {
|
|
|
|
// Don't inline these, since y is not from the pat
|
|
|
|
Some(x) if matches!(y, 1 if true) => ..,
|
|
|
|
Some(x) if let 1 = y => ..,
|
|
|
|
Some(x) if y == 2 => ..,
|
|
|
|
_ => todo!(),
|
|
|
|
};
|
|
|
|
let a = A(1);
|
|
|
|
match a {
|
|
|
|
_ if a.0 == 1 => {},
|
|
|
|
_ => todo!(),
|
|
|
|
}
|
|
|
|
let b = B { e: Some(A(0)) };
|
|
|
|
match b {
|
|
|
|
B { e: Some(A(2)) } => ..,
|
|
|
|
_ => todo!(),
|
|
|
|
};
|
|
|
|
// Do not lint, since we cannot represent this as a pattern (at least, without a conversion)
|
|
|
|
let v = Some(vec![1u8, 2, 3]);
|
|
|
|
match v {
|
|
|
|
Some(x) if x == [1] => {},
|
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
|
|
|
|
external! {
|
|
|
|
let x = Some(Some(1));
|
|
|
|
match x {
|
|
|
|
Some(x) if let Some(1) = x => ..,
|
|
|
|
_ => todo!(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
with_span! {
|
|
|
|
span
|
|
|
|
let x = Some(Some(1));
|
|
|
|
match x {
|
|
|
|
Some(x) if let Some(1) = x => ..,
|
|
|
|
_ => todo!(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum E {
|
|
|
|
A(&'static str),
|
|
|
|
B(&'static str),
|
|
|
|
C(&'static str),
|
|
|
|
}
|
|
|
|
|
|
|
|
fn i() {
|
|
|
|
match E::A("") {
|
|
|
|
// Do not lint
|
|
|
|
E::A(x) | E::B(x) | E::C(x) if x == "from an or pattern" => {},
|
|
|
|
E::A("not from an or pattern") => {},
|
|
|
|
_ => {},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn h(v: Option<u32>) {
|
|
|
|
match v {
|
|
|
|
Some(0) => ..,
|
|
|
|
_ => ..,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do not lint
|
|
|
|
|
|
|
|
fn f(s: Option<std::ffi::OsString>) {
|
|
|
|
match s {
|
|
|
|
Some(x) if x == "a" => {},
|
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct S {
|
|
|
|
a: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialEq for S {
|
|
|
|
fn eq(&self, _: &Self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Eq for S {}
|
|
|
|
|
|
|
|
static CONST_S: S = S { a: 1 };
|
|
|
|
|
|
|
|
fn g(opt_s: Option<S>) {
|
|
|
|
match opt_s {
|
|
|
|
Some(x) if x == CONST_S => {},
|
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
}
|