mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
Ignore lifetimes from differing contexts in needless_lifetimes
This commit is contained in:
parent
85d4b5ac48
commit
09058388de
3 changed files with 28 additions and 0 deletions
|
@ -144,6 +144,10 @@ fn check_fn_inner<'tcx>(
|
|||
.filter(|param| matches!(param.kind, GenericParamKind::Type { .. }));
|
||||
|
||||
for typ in types {
|
||||
if !typ.span.eq_ctxt(span) {
|
||||
return;
|
||||
}
|
||||
|
||||
for pred in generics.bounds_for_param(typ.def_id) {
|
||||
if pred.origin == PredicateOrigin::WhereClause {
|
||||
// has_where_lifetimes checked that this predicate contains no lifetime.
|
||||
|
@ -181,6 +185,10 @@ fn check_fn_inner<'tcx>(
|
|||
}
|
||||
|
||||
if let Some((elidable_lts, usages)) = could_use_elision(cx, sig.decl, body, trait_sig, generics.params) {
|
||||
if usages.iter().any(|usage| !usage.ident.span.eq_ctxt(span)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let lts = elidable_lts
|
||||
.iter()
|
||||
// In principle, the result of the call to `Node::ident` could be `unwrap`ped, as `DefId` should refer to a
|
||||
|
|
|
@ -516,6 +516,16 @@ mod in_macro {
|
|||
|
||||
// no lint on external macro
|
||||
macro_rules::needless_lifetime!();
|
||||
|
||||
macro_rules! expanded_lifetime {
|
||||
($l:lifetime) => {
|
||||
fn f<$l>(arg: &$l str) -> &$l str {
|
||||
arg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expanded_lifetime!('a);
|
||||
}
|
||||
|
||||
mod issue5787 {
|
||||
|
|
|
@ -516,6 +516,16 @@ mod in_macro {
|
|||
|
||||
// no lint on external macro
|
||||
macro_rules::needless_lifetime!();
|
||||
|
||||
macro_rules! expanded_lifetime {
|
||||
($l:lifetime) => {
|
||||
fn f<$l>(arg: &$l str) -> &$l str {
|
||||
arg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expanded_lifetime!('a);
|
||||
}
|
||||
|
||||
mod issue5787 {
|
||||
|
|
Loading…
Reference in a new issue