Skip to content

Commit d553158

Browse files
author
Lukas Markeffsky
committed
fixed tests (again) and added a test that should actually cause a warning for new_ret_no_self
1 parent 54efffc commit d553158

File tree

2 files changed

+40
-23
lines changed

2 files changed

+40
-23
lines changed

tests/ui/methods.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
#![warn(clippy::all, clippy::pedantic, clippy::option_unwrap_used)]
66
#![allow(
77
clippy::blacklisted_name,
8-
dead_code,
8+
unused,
99
clippy::print_stdout,
1010
clippy::non_ascii_literal,
1111
clippy::new_without_default,
1212
clippy::missing_docs_in_private_items,
1313
clippy::needless_pass_by_value,
1414
clippy::default_trait_access,
1515
clippy::use_self,
16-
clippy::new_ret_no_self,
1716
clippy::useless_format,
1817
clippy::wrong_self_convention
1918
)]
@@ -148,6 +147,14 @@ impl AsyncNew {
148147
}
149148
}
150149

150+
struct BadNew;
151+
152+
impl BadNew {
153+
fn new() -> i32 {
154+
0
155+
}
156+
}
157+
151158
impl Mul<T> for T {
152159
type Output = T;
153160
// No error, obviously.

tests/ui/methods.stderr

+31-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: defining a method called `add` on this type; consider implementing the `std::ops::Add` trait or choosing a less ambiguous name
2-
--> $DIR/methods.rs:38:5
2+
--> $DIR/methods.rs:37:5
33
|
44
LL | / pub fn add(self, other: T) -> T {
55
LL | | self
@@ -8,8 +8,18 @@ LL | | }
88
|
99
= note: `-D clippy::should-implement-trait` implied by `-D warnings`
1010

11+
error: methods called `new` usually return `Self`
12+
--> $DIR/methods.rs:153:5
13+
|
14+
LL | / fn new() -> i32 {
15+
LL | | 0
16+
LL | | }
17+
| |_____^
18+
|
19+
= note: `-D clippy::new-ret-no-self` implied by `-D warnings`
20+
1121
error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead
12-
--> $DIR/methods.rs:168:13
22+
--> $DIR/methods.rs:175:13
1323
|
1424
LL | let _ = opt.map(|x| x + 1)
1525
| _____________^
@@ -21,7 +31,7 @@ LL | | .unwrap_or(0);
2131
= note: replace `map(|x| x + 1).unwrap_or(0)` with `map_or(0, |x| x + 1)`
2232

2333
error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead
24-
--> $DIR/methods.rs:172:13
34+
--> $DIR/methods.rs:179:13
2535
|
2636
LL | let _ = opt.map(|x| {
2737
| _____________^
@@ -31,7 +41,7 @@ LL | | ).unwrap_or(0);
3141
| |____________________________^
3242

3343
error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead
34-
--> $DIR/methods.rs:176:13
44+
--> $DIR/methods.rs:183:13
3545
|
3646
LL | let _ = opt.map(|x| x + 1)
3747
| _____________^
@@ -41,15 +51,15 @@ LL | | });
4151
| |__________________^
4252

4353
error: called `map(f).unwrap_or(None)` on an Option value. This can be done more directly by calling `and_then(f)` instead
44-
--> $DIR/methods.rs:181:13
54+
--> $DIR/methods.rs:188:13
4555
|
4656
LL | let _ = opt.map(|x| Some(x + 1)).unwrap_or(None);
4757
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4858
|
4959
= note: replace `map(|x| Some(x + 1)).unwrap_or(None)` with `and_then(|x| Some(x + 1))`
5060

5161
error: called `map(f).unwrap_or(None)` on an Option value. This can be done more directly by calling `and_then(f)` instead
52-
--> $DIR/methods.rs:183:13
62+
--> $DIR/methods.rs:190:13
5363
|
5464
LL | let _ = opt.map(|x| {
5565
| _____________^
@@ -59,7 +69,7 @@ LL | | ).unwrap_or(None);
5969
| |_____________________^
6070

6171
error: called `map(f).unwrap_or(None)` on an Option value. This can be done more directly by calling `and_then(f)` instead
62-
--> $DIR/methods.rs:187:13
72+
--> $DIR/methods.rs:194:13
6373
|
6474
LL | let _ = opt
6575
| _____________^
@@ -70,15 +80,15 @@ LL | | .unwrap_or(None);
7080
= note: replace `map(|x| Some(x + 1)).unwrap_or(None)` with `and_then(|x| Some(x + 1))`
7181

7282
error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead
73-
--> $DIR/methods.rs:198:13
83+
--> $DIR/methods.rs:205:13
7484
|
7585
LL | let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id);
7686
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7787
|
7888
= note: replace `map(|p| format!("{}.", p)).unwrap_or(id)` with `map_or(id, |p| format!("{}.", p))`
7989

8090
error: called `map(f).unwrap_or_else(g)` on an Option value. This can be done more directly by calling `map_or_else(g, f)` instead
81-
--> $DIR/methods.rs:202:13
91+
--> $DIR/methods.rs:209:13
8292
|
8393
LL | let _ = opt.map(|x| x + 1)
8494
| _____________^
@@ -90,7 +100,7 @@ LL | | .unwrap_or_else(|| 0);
90100
= note: replace `map(|x| x + 1).unwrap_or_else(|| 0)` with `map_or_else(|| 0, |x| x + 1)`
91101

92102
error: called `map(f).unwrap_or_else(g)` on an Option value. This can be done more directly by calling `map_or_else(g, f)` instead
93-
--> $DIR/methods.rs:206:13
103+
--> $DIR/methods.rs:213:13
94104
|
95105
LL | let _ = opt.map(|x| {
96106
| _____________^
@@ -100,7 +110,7 @@ LL | | ).unwrap_or_else(|| 0);
100110
| |____________________________________^
101111

102112
error: called `map(f).unwrap_or_else(g)` on an Option value. This can be done more directly by calling `map_or_else(g, f)` instead
103-
--> $DIR/methods.rs:210:13
113+
--> $DIR/methods.rs:217:13
104114
|
105115
LL | let _ = opt.map(|x| x + 1)
106116
| _____________^
@@ -110,7 +120,7 @@ LL | | );
110120
| |_________________^
111121

112122
error: called `filter(p).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(p)` instead.
113-
--> $DIR/methods.rs:240:13
123+
--> $DIR/methods.rs:247:13
114124
|
115125
LL | let _ = v.iter().filter(|&x| *x < 0).next();
116126
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -119,7 +129,7 @@ LL | let _ = v.iter().filter(|&x| *x < 0).next();
119129
= note: replace `filter(|&x| *x < 0).next()` with `find(|&x| *x < 0)`
120130

121131
error: called `filter(p).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(p)` instead.
122-
--> $DIR/methods.rs:243:13
132+
--> $DIR/methods.rs:250:13
123133
|
124134
LL | let _ = v.iter().filter(|&x| {
125135
| _____________^
@@ -129,7 +139,7 @@ LL | | ).next();
129139
| |___________________________^
130140

131141
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
132-
--> $DIR/methods.rs:259:13
142+
--> $DIR/methods.rs:266:13
133143
|
134144
LL | let _ = v.iter().find(|&x| *x < 0).is_some();
135145
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -138,7 +148,7 @@ LL | let _ = v.iter().find(|&x| *x < 0).is_some();
138148
= note: replace `find(|&x| *x < 0).is_some()` with `any(|x| *x < 0)`
139149

140150
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
141-
--> $DIR/methods.rs:262:13
151+
--> $DIR/methods.rs:269:13
142152
|
143153
LL | let _ = v.iter().find(|&x| {
144154
| _____________^
@@ -148,15 +158,15 @@ LL | | ).is_some();
148158
| |______________________________^
149159

150160
error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`.
151-
--> $DIR/methods.rs:268:13
161+
--> $DIR/methods.rs:275:13
152162
|
153163
LL | let _ = v.iter().position(|&x| x < 0).is_some();
154164
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
155165
|
156166
= note: replace `position(|&x| x < 0).is_some()` with `any(|&x| x < 0)`
157167

158168
error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`.
159-
--> $DIR/methods.rs:271:13
169+
--> $DIR/methods.rs:278:13
160170
|
161171
LL | let _ = v.iter().position(|&x| {
162172
| _____________^
@@ -166,15 +176,15 @@ LL | | ).is_some();
166176
| |______________________________^
167177

168178
error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`.
169-
--> $DIR/methods.rs:277:13
179+
--> $DIR/methods.rs:284:13
170180
|
171181
LL | let _ = v.iter().rposition(|&x| x < 0).is_some();
172182
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
173183
|
174184
= note: replace `rposition(|&x| x < 0).is_some()` with `any(|&x| x < 0)`
175185

176186
error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`.
177-
--> $DIR/methods.rs:280:13
187+
--> $DIR/methods.rs:287:13
178188
|
179189
LL | let _ = v.iter().rposition(|&x| {
180190
| _____________^
@@ -184,12 +194,12 @@ LL | | ).is_some();
184194
| |______________________________^
185195

186196
error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message
187-
--> $DIR/methods.rs:295:13
197+
--> $DIR/methods.rs:302:13
188198
|
189199
LL | let _ = opt.unwrap();
190200
| ^^^^^^^^^^^^
191201
|
192202
= note: `-D clippy::option-unwrap-used` implied by `-D warnings`
193203

194-
error: aborting due to 20 previous errors
204+
error: aborting due to 21 previous errors
195205

0 commit comments

Comments
 (0)