-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix unused_trait_names
FP when as
name is from macro input
#14947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
// Skip if the ident of `as` is from a macro's input | ||
&& (!last_segment.ident.span.from_expansion() || ident.span.from_expansion()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reasoning here? Why check only the last segment? For example, the following will still trigger the lint, I'm not sure it should:
macro_rules! mac {
($i:ident) => { use $i::Tr; };
}
mac!(m);
error: importing trait that is only used anonymously
--> tests/ui/unused_trait_names.rs:313:33
|
LL | ($i:ident) => { use $i::Tr; };
| ^^ help: use: `Tr as _`
LL | }
LL | mac!(m);
| ------- in this macro invocation
What do we want to see linted exactly here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original implementation will lint items inside macros. Note that external macros will not be linted, only those locally since users can edit them. I think it is reasonable to ask users to change it to Tr as _
if the as
part is not from the macro input. However, if the as
part is from user input, like as $i
, then it should not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should ignore macros altogether
@@ -73,6 +73,8 @@ impl<'tcx> LateLintPass<'tcx> for UnusedTraitNames { | |||
&& let Some(snip) = snippet_opt(cx, last_segment.ident.span) | |||
&& self.msrv.meets(cx, msrvs::UNDERSCORE_IMPORTS) | |||
&& !is_from_proc_macro(cx, &last_segment.ident) | |||
// Skip if the ident of `as` is from a macro's input |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment does not seem to correspond to the test which also checks the last segment.
Closes #14924
changelog: [
unused_trait_names
] fix FP whenas
name is from macro input