You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a specific trait is brought into the scope just because it extends some type, but not used directly, alias it as an anonymous _. I have frequently seen it with the common for std::io::Write:
use std::io::Write as _; // <-- don't introduce the "Write" trait into the scope
fn main() {
std::io::stdout().write_all(b"Hello, world!").unwrap();
}
Lint Name
use_non_polluting_alias_for_traits
Category
No response
Advantage
does not introduce (directly) unused traits into the scope
Drawbacks
No response
Example
For trait methods like
mod ext {pubtraitFoo{fnfoo(&self){println!("foo");}}implFoofori32{}}
This example
fnmain(){usecrate::ext::Foo;// <- no aliasing, polluting42.foo();}
What it does
If a specific trait is brought into the scope just because it extends some type, but not used directly, alias it as an anonymous
_
. I have frequently seen it with the common forstd::io::Write
:Lint Name
use_non_polluting_alias_for_traits
Category
No response
Advantage
Drawbacks
No response
Example
For trait methods like
This example
Could be written as:
The text was updated successfully, but these errors were encountered: