mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-18 00:53:31 +00:00
Auto merge of #10380 - Alexendoo:needless-lifetime-macro-expansion, r=xFrednet
Ignore lifetimes from differing contexts in `needless_lifetimes` Fixes #10379 changelog: [`needless_lifetimes`]: Don't lint signatures in macros if the lifetime is a metavariable
This commit is contained in:
commit
803ce88477
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 { .. }));
|
.filter(|param| matches!(param.kind, GenericParamKind::Type { .. }));
|
||||||
|
|
||||||
for typ in types {
|
for typ in types {
|
||||||
|
if !typ.span.eq_ctxt(span) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for pred in generics.bounds_for_param(typ.def_id) {
|
for pred in generics.bounds_for_param(typ.def_id) {
|
||||||
if pred.origin == PredicateOrigin::WhereClause {
|
if pred.origin == PredicateOrigin::WhereClause {
|
||||||
// has_where_lifetimes checked that this predicate contains no lifetime.
|
// 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 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
|
let lts = elidable_lts
|
||||||
.iter()
|
.iter()
|
||||||
// In principle, the result of the call to `Node::ident` could be `unwrap`ped, as `DefId` should refer to a
|
// 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
|
// no lint on external macro
|
||||||
macro_rules::needless_lifetime!();
|
macro_rules::needless_lifetime!();
|
||||||
|
|
||||||
|
macro_rules! expanded_lifetime {
|
||||||
|
($l:lifetime) => {
|
||||||
|
fn f<$l>(arg: &$l str) -> &$l str {
|
||||||
|
arg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expanded_lifetime!('a);
|
||||||
}
|
}
|
||||||
|
|
||||||
mod issue5787 {
|
mod issue5787 {
|
||||||
|
|
|
@ -516,6 +516,16 @@ mod in_macro {
|
||||||
|
|
||||||
// no lint on external macro
|
// no lint on external macro
|
||||||
macro_rules::needless_lifetime!();
|
macro_rules::needless_lifetime!();
|
||||||
|
|
||||||
|
macro_rules! expanded_lifetime {
|
||||||
|
($l:lifetime) => {
|
||||||
|
fn f<$l>(arg: &$l str) -> &$l str {
|
||||||
|
arg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expanded_lifetime!('a);
|
||||||
}
|
}
|
||||||
|
|
||||||
mod issue5787 {
|
mod issue5787 {
|
||||||
|
|
Loading…
Reference in a new issue