Skip to content

Commit d7246b0

Browse files
authored
Do not check for unused lifetimes in expanded code (#17256)
changelog: [`extra_unused_lifetimes`]: do not lint the expanded code Fixes #17255
2 parents faaf6d6 + 830e6eb commit d7246b0

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

clippy_lints/src/lifetimes.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes {
161161
}
162162

163163
fn check_poly_trait_ref(&mut self, cx: &LateContext<'tcx>, poly_trait_ref: &'tcx PolyTraitRef<'tcx>) {
164-
report_extra_trait_object_lifetimes(cx, poly_trait_ref.bound_generic_params, &poly_trait_ref.trait_ref);
164+
if !poly_trait_ref.span.from_expansion() {
165+
report_extra_trait_object_lifetimes(cx, poly_trait_ref.bound_generic_params, &poly_trait_ref.trait_ref);
166+
}
165167
}
166168

167169
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {

tests/ui/extra_unused_lifetimes.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,18 @@ mod proc_macro_generated {
211211
}
212212
}
213213

214+
mod issue17255 {
215+
216+
trait AnotherSimpleTrait<'a> {}
217+
218+
macro_rules! mac {
219+
($lt:lifetime, $t:ident, $tr:path) => {
220+
impl<$t: for<'lt> $tr> AnotherSimpleTrait<'_> for $t {}
221+
};
222+
}
223+
224+
// Do not lint code expanded from macros
225+
mac!('a, T, super::SimplerTrait);
226+
}
227+
214228
fn main() {}

0 commit comments

Comments
 (0)