Skip to content

Commit 2bfcf89

Browse files
committed
Merge branch 'origin/master' into flat-map
2 parents 2fe5e2c + c154754 commit 2bfcf89

File tree

6 files changed

+68
-28
lines changed

6 files changed

+68
-28
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,11 +1094,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
10941094
(Predicate::Projection(poly_projection_predicate), _) => {
10951095
let binder = poly_projection_predicate.ty();
10961096
let associated_type = binder.skip_binder();
1097-
let associated_type_is_self_type = same_tys(cx, ty, associated_type);
10981097

1099-
// if the associated type is self, early return and do not trigger lint
1100-
if associated_type_is_self_type {
1101-
return;
1098+
// walk the associated type and check for Self
1099+
for inner_type in associated_type.walk() {
1100+
if same_tys(cx, ty, inner_type) {
1101+
return;
1102+
}
11021103
}
11031104
},
11041105
(_, _) => {},

clippy_lints/src/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ declare_clippy_lint! {
7373
/// lint is to catch debugging remnants.
7474
///
7575
/// **Why is this bad?** The purpose of the `Debug` trait is to facilitate
76-
/// debugging Rust code. It should not be used in in user-facing output.
76+
/// debugging Rust code. It should not be used in user-facing output.
7777
///
7878
/// **Example:**
7979
/// ```rust

doc/adding_lints.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ because that's clearly a non-descriptive name.
1010
* [Setup](#Setup)
1111
* [Testing](#Testing)
1212
* [Rustfix tests](#Rustfix-tests)
13+
* [Edition 2018 tests](#Edition-2018-tests)
1314
* [Lint declaration](#Lint-declaration)
1415
* [Lint passes](#Lint-passes)
1516
* [Emitting a lint](#Emitting-a-lint)
@@ -101,6 +102,12 @@ Use `tests/ui/update-all-references.sh` to automatically generate the
101102

102103
With tests in place, let's have a look at implementing our lint now.
103104

105+
### Edition 2018 tests
106+
107+
Some features require the 2018 edition to work (e.g. `async_await`), but
108+
compile-test tests run on the 2015 edition by default. To change this behavior
109+
add `// compile-flags: --edition 2018` at the top of the test file.
110+
104111
### Testing manually
105112

106113
Manually testing against an example file can be useful if you have added some

tests/ui/methods.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// aux-build:option_helpers.rs
2+
// compile-flags: --edition 2018
23

4+
#![feature(async_await)]
35
#![warn(clippy::all, clippy::pedantic, clippy::option_unwrap_used)]
46
#![allow(
57
clippy::blacklisted_name,
@@ -11,7 +13,6 @@
1113
clippy::needless_pass_by_value,
1214
clippy::default_trait_access,
1315
clippy::use_self,
14-
clippy::new_ret_no_self,
1516
clippy::useless_format,
1617
clippy::wrong_self_convention
1718
)]
@@ -138,6 +139,22 @@ impl<T> V<T> {
138139
}
139140
}
140141

142+
struct AsyncNew;
143+
144+
impl AsyncNew {
145+
async fn new() -> Option<Self> {
146+
None
147+
}
148+
}
149+
150+
struct BadNew;
151+
152+
impl BadNew {
153+
fn new() -> i32 {
154+
0
155+
}
156+
}
157+
141158
impl Mul<T> for T {
142159
type Output = T;
143160
// No error, obviously.

tests/ui/methods.stderr

Lines changed: 31 additions & 21 deletions
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:36: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:158: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:162: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:166: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:171: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:173: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:177: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:188: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:192: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:196: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:200: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:230: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:233: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:249: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:252: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:258: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:261: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:267: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:270: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:285: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

util/fetch_prs_between.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ IFS='
1414
for pr in $(git log --oneline --grep "Merge #" --grep "Merge pull request" --grep "Auto merge of" "$first...$last" | sort -rn | uniq); do
1515
id=$(echo $pr | rg -o '#[0-9]{3,5}' | cut -c 2-)
1616
commit=$(echo $pr | cut -d' ' -f 1)
17+
message=$(git --no-pager show --pretty=medium $commit)
18+
if [ ! -z $(echo "$message" | rg "^[\s]{4}changelog: [nN]one\.*$") ]; then
19+
continue
20+
fi
21+
1722
echo "URL: https://github.com/rust-lang/rust-clippy/pull/$id"
18-
echo "$(git --no-pager show --pretty=medium $commit)"
23+
echo "$message"
1924
echo "---------------------------------------------------------\n"
2025
done

0 commit comments

Comments
 (0)