]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/equatable_if_let.fixed
Rollup merge of #89876 - AlexApps99:const_ops, r=oli-obk
[rust.git] / src / tools / clippy / tests / ui / equatable_if_let.fixed
1 // run-rustfix
2
3 #![allow(unused_variables, dead_code)]
4 #![warn(clippy::equatable_if_let)]
5
6 use std::cmp::Ordering;
7
8 #[derive(PartialEq)]
9 enum Enum {
10     TupleVariant(i32, u64),
11     RecordVariant { a: i64, b: u32 },
12     UnitVariant,
13     Recursive(Struct),
14 }
15
16 #[derive(PartialEq)]
17 struct Struct {
18     a: i32,
19     b: bool,
20 }
21
22 enum NotPartialEq {
23     A,
24     B,
25 }
26
27 enum NotStructuralEq {
28     A,
29     B,
30 }
31
32 impl PartialEq for NotStructuralEq {
33     fn eq(&self, _: &NotStructuralEq) -> bool {
34         false
35     }
36 }
37
38 fn main() {
39     let a = 2;
40     let b = 3;
41     let c = Some(2);
42     let d = Struct { a: 2, b: false };
43     let e = Enum::UnitVariant;
44     let f = NotPartialEq::A;
45     let g = NotStructuralEq::A;
46
47     // true
48
49     if a == 2 {}
50     if a.cmp(&b) == Ordering::Greater {}
51     if c == Some(2) {}
52     if d == (Struct { a: 2, b: false }) {}
53     if e == Enum::TupleVariant(32, 64) {}
54     if e == (Enum::RecordVariant { a: 64, b: 32 }) {}
55     if e == Enum::UnitVariant {}
56     if (e, &d) == (Enum::UnitVariant, &Struct { a: 2, b: false }) {}
57
58     // false
59
60     if let 2 | 3 = a {}
61     if let x @ 2 = a {}
62     if let Some(3 | 4) = c {}
63     if let Struct { a, b: false } = d {}
64     if let Struct { a: 2, b: x } = d {}
65     if let NotPartialEq::A = f {}
66     if g == NotStructuralEq::A {}
67     if let Some(NotPartialEq::A) = Some(f) {}
68     if Some(g) == Some(NotStructuralEq::A) {}
69
70     macro_rules! m1 {
71         (x) => {
72             "abc"
73         };
74     }
75     if "abc" == m1!(x) {
76         println!("OK");
77     }
78 }