Skip to content

Commit abbcea8

Browse files
committed
Add new ui tests
1 parent f75d1b2 commit abbcea8

File tree

2 files changed

+106
-19
lines changed

2 files changed

+106
-19
lines changed

tests/ui/bool_assert_comparison.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![warn(clippy::bool_assert_comparison)]
22

3+
use std::ops::Not;
4+
35
macro_rules! a {
46
() => {
57
true
@@ -11,14 +13,67 @@ macro_rules! b {
1113
};
1214
}
1315

16+
// Implements the Not trait but with an output type
17+
// that's not bool. Should not suggest a rewrite
18+
#[derive(Debug)]
19+
enum A {
20+
VariantX(bool),
21+
VariantY(u32),
22+
}
23+
24+
impl PartialEq<bool> for A {
25+
fn eq(&self, other: &bool) -> bool {
26+
match *self {
27+
A::VariantX(b) => b == *other,
28+
_ => false,
29+
}
30+
}
31+
}
32+
33+
impl Not for A {
34+
type Output = Self;
35+
36+
fn not(self) -> Self::Output {
37+
match self {
38+
A::VariantX(b) => A::VariantX(!b),
39+
A::VariantY(0) => A::VariantY(1),
40+
A::VariantY(_) => A::VariantY(0),
41+
}
42+
}
43+
}
44+
45+
// This type implements the Not trait with an Output of
46+
// type bool. Using assert!(..) must be suggested
47+
#[derive(Debug)]
48+
struct B;
49+
50+
impl PartialEq<bool> for B {
51+
fn eq(&self, other: &bool) -> bool {
52+
false
53+
}
54+
}
55+
56+
impl Not for B {
57+
type Output = bool;
58+
59+
fn not(self) -> Self::Output {
60+
true
61+
}
62+
}
63+
1464
fn main() {
65+
let a = A::VariantX(true);
66+
let b = B {};
67+
1568
assert_eq!("a".len(), 1);
1669
assert_eq!("a".is_empty(), false);
1770
assert_eq!("".is_empty(), true);
1871
assert_eq!(true, "".is_empty());
1972
assert_eq!(a!(), b!());
2073
assert_eq!(a!(), "".is_empty());
2174
assert_eq!("".is_empty(), b!());
75+
assert_eq!(a, true);
76+
assert_eq!(b, true);
2277

2378
assert_ne!("a".len(), 1);
2479
assert_ne!("a".is_empty(), false);
@@ -27,6 +82,8 @@ fn main() {
2782
assert_ne!(a!(), b!());
2883
assert_ne!(a!(), "".is_empty());
2984
assert_ne!("".is_empty(), b!());
85+
assert_ne!(a, true);
86+
assert_ne!(b, true);
3087

3188
debug_assert_eq!("a".len(), 1);
3289
debug_assert_eq!("a".is_empty(), false);
@@ -35,6 +92,8 @@ fn main() {
3592
debug_assert_eq!(a!(), b!());
3693
debug_assert_eq!(a!(), "".is_empty());
3794
debug_assert_eq!("".is_empty(), b!());
95+
debug_assert_eq!(a, true);
96+
debug_assert_eq!(b, true);
3897

3998
debug_assert_ne!("a".len(), 1);
4099
debug_assert_ne!("a".is_empty(), false);
@@ -43,17 +102,21 @@ fn main() {
43102
debug_assert_ne!(a!(), b!());
44103
debug_assert_ne!(a!(), "".is_empty());
45104
debug_assert_ne!("".is_empty(), b!());
105+
debug_assert_ne!(a, true);
106+
debug_assert_ne!(b, true);
46107

47108
// assert with error messages
48109
assert_eq!("a".len(), 1, "tadam {}", 1);
49110
assert_eq!("a".len(), 1, "tadam {}", true);
50111
assert_eq!("a".is_empty(), false, "tadam {}", 1);
51112
assert_eq!("a".is_empty(), false, "tadam {}", true);
52113
assert_eq!(false, "a".is_empty(), "tadam {}", true);
114+
assert_eq!(a, true, "tadam {}", false);
53115

54116
debug_assert_eq!("a".len(), 1, "tadam {}", 1);
55117
debug_assert_eq!("a".len(), 1, "tadam {}", true);
56118
debug_assert_eq!("a".is_empty(), false, "tadam {}", 1);
57119
debug_assert_eq!("a".is_empty(), false, "tadam {}", true);
58120
debug_assert_eq!(false, "a".is_empty(), "tadam {}", true);
121+
debug_assert_eq!(a, true, "tadam {}", false);
59122
}
Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,136 @@
11
error: used `assert_eq!` with a literal bool
2-
--> $DIR/bool_assert_comparison.rs:16:5
2+
--> $DIR/bool_assert_comparison.rs:69:5
33
|
44
LL | assert_eq!("a".is_empty(), false);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)`
66
|
77
= note: `-D clippy::bool-assert-comparison` implied by `-D warnings`
88

99
error: used `assert_eq!` with a literal bool
10-
--> $DIR/bool_assert_comparison.rs:17:5
10+
--> $DIR/bool_assert_comparison.rs:70:5
1111
|
1212
LL | assert_eq!("".is_empty(), true);
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)`
1414

1515
error: used `assert_eq!` with a literal bool
16-
--> $DIR/bool_assert_comparison.rs:18:5
16+
--> $DIR/bool_assert_comparison.rs:71:5
1717
|
1818
LL | assert_eq!(true, "".is_empty());
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)`
2020

21+
error: used `assert_eq!` with a literal bool
22+
--> $DIR/bool_assert_comparison.rs:76:5
23+
|
24+
LL | assert_eq!(b, true);
25+
| ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)`
26+
2127
error: used `assert_ne!` with a literal bool
22-
--> $DIR/bool_assert_comparison.rs:24:5
28+
--> $DIR/bool_assert_comparison.rs:79:5
2329
|
2430
LL | assert_ne!("a".is_empty(), false);
2531
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)`
2632

2733
error: used `assert_ne!` with a literal bool
28-
--> $DIR/bool_assert_comparison.rs:25:5
34+
--> $DIR/bool_assert_comparison.rs:80:5
2935
|
3036
LL | assert_ne!("".is_empty(), true);
3137
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)`
3238

3339
error: used `assert_ne!` with a literal bool
34-
--> $DIR/bool_assert_comparison.rs:26:5
40+
--> $DIR/bool_assert_comparison.rs:81:5
3541
|
3642
LL | assert_ne!(true, "".is_empty());
3743
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)`
3844

45+
error: used `assert_ne!` with a literal bool
46+
--> $DIR/bool_assert_comparison.rs:86:5
47+
|
48+
LL | assert_ne!(b, true);
49+
| ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)`
50+
3951
error: used `debug_assert_eq!` with a literal bool
40-
--> $DIR/bool_assert_comparison.rs:32:5
52+
--> $DIR/bool_assert_comparison.rs:89:5
4153
|
4254
LL | debug_assert_eq!("a".is_empty(), false);
4355
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)`
4456

4557
error: used `debug_assert_eq!` with a literal bool
46-
--> $DIR/bool_assert_comparison.rs:33:5
58+
--> $DIR/bool_assert_comparison.rs:90:5
4759
|
4860
LL | debug_assert_eq!("".is_empty(), true);
4961
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)`
5062

5163
error: used `debug_assert_eq!` with a literal bool
52-
--> $DIR/bool_assert_comparison.rs:34:5
64+
--> $DIR/bool_assert_comparison.rs:91:5
5365
|
5466
LL | debug_assert_eq!(true, "".is_empty());
5567
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)`
5668

69+
error: used `debug_assert_eq!` with a literal bool
70+
--> $DIR/bool_assert_comparison.rs:96:5
71+
|
72+
LL | debug_assert_eq!(b, true);
73+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)`
74+
5775
error: used `debug_assert_ne!` with a literal bool
58-
--> $DIR/bool_assert_comparison.rs:40:5
76+
--> $DIR/bool_assert_comparison.rs:99:5
5977
|
6078
LL | debug_assert_ne!("a".is_empty(), false);
6179
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)`
6280

6381
error: used `debug_assert_ne!` with a literal bool
64-
--> $DIR/bool_assert_comparison.rs:41:5
82+
--> $DIR/bool_assert_comparison.rs:100:5
6583
|
6684
LL | debug_assert_ne!("".is_empty(), true);
6785
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)`
6886

6987
error: used `debug_assert_ne!` with a literal bool
70-
--> $DIR/bool_assert_comparison.rs:42:5
88+
--> $DIR/bool_assert_comparison.rs:101:5
7189
|
7290
LL | debug_assert_ne!(true, "".is_empty());
7391
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)`
7492

93+
error: used `debug_assert_ne!` with a literal bool
94+
--> $DIR/bool_assert_comparison.rs:106:5
95+
|
96+
LL | debug_assert_ne!(b, true);
97+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)`
98+
7599
error: used `assert_eq!` with a literal bool
76-
--> $DIR/bool_assert_comparison.rs:50:5
100+
--> $DIR/bool_assert_comparison.rs:111:5
77101
|
78102
LL | assert_eq!("a".is_empty(), false, "tadam {}", 1);
79103
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)`
80104

81105
error: used `assert_eq!` with a literal bool
82-
--> $DIR/bool_assert_comparison.rs:51:5
106+
--> $DIR/bool_assert_comparison.rs:112:5
83107
|
84108
LL | assert_eq!("a".is_empty(), false, "tadam {}", true);
85109
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)`
86110

87111
error: used `assert_eq!` with a literal bool
88-
--> $DIR/bool_assert_comparison.rs:52:5
112+
--> $DIR/bool_assert_comparison.rs:113:5
89113
|
90114
LL | assert_eq!(false, "a".is_empty(), "tadam {}", true);
91115
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `assert!(..)`
92116

93117
error: used `debug_assert_eq!` with a literal bool
94-
--> $DIR/bool_assert_comparison.rs:56:5
118+
--> $DIR/bool_assert_comparison.rs:118:5
95119
|
96120
LL | debug_assert_eq!("a".is_empty(), false, "tadam {}", 1);
97121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)`
98122

99123
error: used `debug_assert_eq!` with a literal bool
100-
--> $DIR/bool_assert_comparison.rs:57:5
124+
--> $DIR/bool_assert_comparison.rs:119:5
101125
|
102126
LL | debug_assert_eq!("a".is_empty(), false, "tadam {}", true);
103127
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)`
104128

105129
error: used `debug_assert_eq!` with a literal bool
106-
--> $DIR/bool_assert_comparison.rs:58:5
130+
--> $DIR/bool_assert_comparison.rs:120:5
107131
|
108132
LL | debug_assert_eq!(false, "a".is_empty(), "tadam {}", true);
109133
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `debug_assert!(..)`
110134

111-
error: aborting due to 18 previous errors
135+
error: aborting due to 22 previous errors
112136

0 commit comments

Comments
 (0)