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