]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/equatable_if_let.rs
Rollup merge of #98583 - joshtriplett:stabilize-windows-symlink-types, r=thomcc
[rust.git] / src / tools / clippy / tests / ui / equatable_if_let.rs
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 let 2 = a {}
54     if let Ordering::Greater = a.cmp(&b) {}
55     if let Some(2) = c {}
56     if let Struct { a: 2, b: false } = d {}
57     if let Enum::TupleVariant(32, 64) = e {}
58     if let Enum::RecordVariant { a: 64, b: 32 } = e {}
59     if let Enum::UnitVariant = e {}
60     if let (Enum::UnitVariant, &Struct { a: 2, b: false }) = (e, &d) {}
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 let NotStructuralEq::A = g {}
71     if let Some(NotPartialEq::A) = Some(f) {}
72     if let Some(NotStructuralEq::A) = Some(g) {}
73
74     macro_rules! m1 {
75         (x) => {
76             "abc"
77         };
78     }
79     if let m1!(x) = "abc" {
80         println!("OK");
81     }
82
83     equatable_if_let!(a);
84 }