Skip to content

Commit b600c08

Browse files
committed
fix: unused_trait_names FP when as name is from macro input
1 parent 57cbadd commit b600c08

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

clippy_lints/src/unused_trait_names.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ impl<'tcx> LateLintPass<'tcx> for UnusedTraitNames {
7373
&& let Some(snip) = snippet_opt(cx, last_segment.ident.span)
7474
&& self.msrv.meets(cx, msrvs::UNDERSCORE_IMPORTS)
7575
&& !is_from_proc_macro(cx, &last_segment.ident)
76+
// Skip if the ident of `as` is from a macro's input
77+
&& !(last_segment.ident.span.from_expansion() && !ident.span.from_expansion())
7678
{
7779
let complete_span = last_segment.ident.span.to(ident.span);
7880
span_lint_and_sugg(

tests/ui/unused_trait_names.fixed

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,22 @@ mod allow_lint_import {
294294
// "foo".type_id();
295295
// }
296296
// }
297+
298+
mod issue14924 {
299+
mod m {
300+
pub trait Tr {
301+
fn method(&self) {}
302+
}
303+
304+
impl Tr for u8 {}
305+
}
306+
307+
macro gen_import($Br: ident) {
308+
use m::Tr as $Br;
309+
}
310+
gen_import!(Br);
311+
312+
fn do_something() {
313+
0u8.method();
314+
}
315+
}

tests/ui/unused_trait_names.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,22 @@ mod allow_lint_import {
294294
// "foo".type_id();
295295
// }
296296
// }
297+
298+
mod issue14924 {
299+
mod m {
300+
pub trait Tr {
301+
fn method(&self) {}
302+
}
303+
304+
impl Tr for u8 {}
305+
}
306+
307+
macro gen_import($Br: ident) {
308+
use m::Tr as $Br;
309+
}
310+
gen_import!(Br);
311+
312+
fn do_something() {
313+
0u8.method();
314+
}
315+
}

0 commit comments

Comments
 (0)