-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Summary
.
Lint Name
unused_trait_names
Reproducer
I tried this code:
#![warn(clippy::unused_trait_names)]
#![feature(decl_macro)]
mod m {
pub trait Tr {
fn method(&self) {}
}
impl Tr for u8 {}
}
macro gen_import($Br: ident) {
use m::Tr as $Br;
}
gen_import!(Br);
fn main() {
0u8.method();
}
I saw this happen:
warning: importing trait that is only used anonymously
--> src/main.rs:13:12
|
13 | use m::Tr as $Br;
| ^^ help: use: `Tr as _`
14 | }
15 | gen_import!(Br);
| --------------- in this macro invocation
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_trait_names
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(clippy::unused_trait_names)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this warning originates in the macro `gen_import` (in Nightly builds, run with -Z macro-backtrace for more info)
suggestion
#![warn(clippy::unused_trait_names)]
#![feature(decl_macro)]
mod m {
pub trait Tr {
fn method(&self) {}
}
impl Tr for u8 {}
}
macro gen_import($Br: ident) {
use m::Tr as _ as $Br;
}
gen_import!(Br);
fn main() {
0u8.method();
}
does not compile
error: expected `;`, found keyword `as`
--> src/main.rs:13:20
|
13 | use m::Tr as _ as $Br;
| ^^ expected `;`
14 | }
15 | gen_import!(Br);
| --------------- in this macro invocation
|
= note: this error originates in the macro `gen_import` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0599]: no method named `method` found for type `u8` in the current scope
--> src/main.rs:18:9
|
6 | fn method(&self) {}
| ------ the method is available for `u8` here
...
18 | 0u8.method();
| ^^^^^^ method not found in `u8`error: expected `;`, found keyword `as`
--> src/main.rs:13:20
|
13 | use m::Tr as _ as $Br;
| ^^ expected `;`
14 | }
15 | gen_import!(Br);
| --------------- in this macro invocation
|
= note: this error originates in the macro `gen_import` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0599]: no method named `method` found for type `u8` in the current scope
--> src/main.rs:18:9
|
6 | fn method(&self) {}
| ------ the method is available for `u8` here
...
18 | 0u8.method();
| ^^^^^^ method not found in `u8`
|
= help: items from traits can only be used if the trait is in scope
help: trait `Tr` which provides `method` is implemented but not in scope; perhaps you want to import it
|
4 + use crate::m::Tr;
|
For more information about this error, try `rustc --explain E0599`.
|
= help: items from traits can only be used if the trait is in scope
help: trait `Tr` which provides `method` is implemented but not in scope; perhaps you want to import it
|
4 + use crate::m::Tr;
|
For more information about this error, try `rustc --explain E0599`.
Version
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have