File tree 5 files changed +114
-101
lines changed
5 files changed +114
-101
lines changed Original file line number Diff line number Diff line change 1
1
use clippy_utils:: diagnostics:: { span_lint, span_lint_and_then} ;
2
2
use clippy_utils:: trait_ref_of_method;
3
+ use itertools:: Itertools ;
3
4
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
4
5
use rustc_errors:: Applicability ;
5
6
use rustc_hir:: intravisit:: nested_filter:: { self as hir_nested_filter, NestedFilter } ;
@@ -201,7 +202,19 @@ fn check_fn_inner<'tcx>(
201
202
span_lint_and_then (
202
203
cx,
203
204
NEEDLESS_LIFETIMES ,
204
- span. with_hi ( sig. decl . output . span ( ) . hi ( ) ) ,
205
+ elidable_lts
206
+ . iter ( )
207
+ . map ( |& lt| cx. tcx . def_span ( lt) )
208
+ . chain ( usages. iter ( ) . filter_map ( |usage| {
209
+ if let LifetimeName :: Param ( def_id) = usage. res
210
+ && elidable_lts. contains ( & def_id)
211
+ {
212
+ return Some ( usage. ident . span ) ;
213
+ }
214
+
215
+ None
216
+ } ) )
217
+ . collect_vec ( ) ,
205
218
& format ! ( "the following explicit lifetimes could be elided: {lts}" ) ,
206
219
|diag| {
207
220
if sig. header . is_async ( ) {
Original file line number Diff line number Diff line change 1
1
error: the following explicit lifetimes could be elided: 'a
2
- --> $DIR/ice-2774.rs:15:1
2
+ --> $DIR/ice-2774.rs:15:28
3
3
|
4
4
LL | pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) {
5
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^
5
+ | ^^ ^^
6
6
|
7
7
= note: `-D clippy::needless-lifetimes` implied by `-D warnings`
8
8
help: elide the lifetimes
Original file line number Diff line number Diff line change 1
1
error: the following explicit lifetimes could be elided: 'a
2
- --> $DIR/needless_lifetimes_impl_trait.rs:15:5
2
+ --> $DIR/needless_lifetimes_impl_trait.rs:15:12
3
3
|
4
4
LL | fn baz<'a>(&'a self) -> impl Foo + 'a {
5
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^
5
+ | ^^ ^^ ^^
6
6
|
7
7
note: the lint level is defined here
8
8
--> $DIR/needless_lifetimes_impl_trait.rs:1:9
Original file line number Diff line number Diff line change 1
1
error: the following explicit lifetimes could be elided: 'a
2
- --> $DIR/issue_4266.rs:4:1
2
+ --> $DIR/issue_4266.rs:4:16
3
3
|
4
4
LL | async fn sink1<'a>(_: &'a str) {} // lint
5
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^
5
+ | ^^ ^^
6
6
|
7
7
= note: `-D clippy::needless-lifetimes` implied by `-D warnings`
8
8
9
9
error: the following explicit lifetimes could be elided: 'a
10
- --> $DIR/issue_4266.rs:8:1
10
+ --> $DIR/issue_4266.rs:8:21
11
11
|
12
12
LL | async fn one_to_one<'a>(s: &'a str) -> &'a str {
13
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^
13
+ | ^^ ^^
14
14
15
15
error: methods called `new` usually take no `self`
16
16
--> $DIR/issue_4266.rs:28:22
You can’t perform that action at this time.
0 commit comments