]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/eq_op_macros.rs
Auto merge of #102536 - scottmcm:lookup_line-tweak, r=jackh726
[rust.git] / src / tools / clippy / tests / ui / eq_op_macros.rs
1 #![warn(clippy::eq_op)]
2
3 // lint also in macro definition
4 macro_rules! assert_in_macro_def {
5     () => {
6         let a = 42;
7         assert_eq!(a, a);
8         assert_ne!(a, a);
9         debug_assert_eq!(a, a);
10         debug_assert_ne!(a, a);
11     };
12 }
13
14 // lint identical args in assert-like macro invocations (see #3574)
15 fn main() {
16     assert_in_macro_def!();
17
18     let a = 1;
19     let b = 2;
20
21     // lint identical args in `assert_eq!`
22     assert_eq!(a, a);
23     assert_eq!(a + 1, a + 1);
24     // ok
25     assert_eq!(a, b);
26     assert_eq!(a, a + 1);
27     assert_eq!(a + 1, b + 1);
28
29     // lint identical args in `assert_ne!`
30     assert_ne!(a, a);
31     assert_ne!(a + 1, a + 1);
32     // ok
33     assert_ne!(a, b);
34     assert_ne!(a, a + 1);
35     assert_ne!(a + 1, b + 1);
36
37     // lint identical args in `debug_assert_eq!`
38     debug_assert_eq!(a, a);
39     debug_assert_eq!(a + 1, a + 1);
40     // ok
41     debug_assert_eq!(a, b);
42     debug_assert_eq!(a, a + 1);
43     debug_assert_eq!(a + 1, b + 1);
44
45     // lint identical args in `debug_assert_ne!`
46     debug_assert_ne!(a, a);
47     debug_assert_ne!(a + 1, a + 1);
48     // ok
49     debug_assert_ne!(a, b);
50     debug_assert_ne!(a, a + 1);
51     debug_assert_ne!(a + 1, b + 1);
52
53     let my_vec = vec![1; 5];
54     let mut my_iter = my_vec.iter();
55     assert_ne!(my_iter.next(), my_iter.next());
56 }