File tree Expand file tree Collapse file tree 5 files changed +114
-101
lines changed Expand file tree Collapse file tree 5 files changed +114
-101
lines changed Original file line number Diff line number Diff line change 11use clippy_utils:: diagnostics:: { span_lint, span_lint_and_then} ;
22use clippy_utils:: trait_ref_of_method;
3+ use itertools:: Itertools ;
34use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
45use rustc_errors:: Applicability ;
56use rustc_hir:: intravisit:: nested_filter:: { self as hir_nested_filter, NestedFilter } ;
@@ -201,7 +202,19 @@ fn check_fn_inner<'tcx>(
201202 span_lint_and_then (
202203 cx,
203204 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 ( ) ,
205218 & format ! ( "the following explicit lifetimes could be elided: {lts}" ) ,
206219 |diag| {
207220 if sig. header . is_async ( ) {
Original file line number Diff line number Diff line change 11error: the following explicit lifetimes could be elided: 'a
2- --> $DIR/ice-2774.rs:15:1
2+ --> $DIR/ice-2774.rs:15:28
33 |
44LL | pub fn add_barfoos_to_foos<'a>(bars: &HashSet<&'a Bar>) {
5- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^
5+ | ^^ ^^
66 |
77 = note: `-D clippy::needless-lifetimes` implied by `-D warnings`
88help: elide the lifetimes
Original file line number Diff line number Diff line change 11error: 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
33 |
44LL | fn baz<'a>(&'a self) -> impl Foo + 'a {
5- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^
5+ | ^^ ^^ ^^
66 |
77note: the lint level is defined here
88 --> $DIR/needless_lifetimes_impl_trait.rs:1:9
Original file line number Diff line number Diff line change 11error: the following explicit lifetimes could be elided: 'a
2- --> $DIR/issue_4266.rs:4:1
2+ --> $DIR/issue_4266.rs:4:16
33 |
44LL | async fn sink1<'a>(_: &'a str) {} // lint
5- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^
5+ | ^^ ^^
66 |
77 = note: `-D clippy::needless-lifetimes` implied by `-D warnings`
88
99error: the following explicit lifetimes could be elided: 'a
10- --> $DIR/issue_4266.rs:8:1
10+ --> $DIR/issue_4266.rs:8:21
1111 |
1212LL | async fn one_to_one<'a>(s: &'a str) -> &'a str {
13- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^
13+ | ^^ ^^
1414
1515error: methods called `new` usually take no `self`
1616 --> $DIR/issue_4266.rs:28:22
You can’t perform that action at this time.
0 commit comments