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 trait is imported only for its methods but not its name directly, append as _ to the import
Lint Name
unname_method_only_trait_imports
Category
style
Advantage
The imported name isn't actually used. Keeping it would result in conflicts in the future when other items with the same identifier are imported, at which point developers have to corrupt the commit diff to modify it
Some names are used at really high frequency, e.g. anyhow::Context. In fact, the last 5 times I ran into name collision, it was to do with anyhow::Context.
Drawbacks
Editors do not support this right now, implying that we need a cargo fix for this to be useful.
Example
mod universe {use anyhow::{Context,Result};fnfoo() -> Result<()>{
fs::remove_file("file").context("unlink")}}
Could be written as:
mod universe {use anyhow::{Contextas _,Result};fnfoo() -> Result<()>{
fs::remove_file("file").context("unlink")}}
The text was updated successfully, but these errors were encountered:
What it does
If a trait is imported only for its methods but not its name directly, append
as _
to the importLint Name
unname_method_only_trait_imports
Category
style
Advantage
anyhow::Context
. In fact, the last 5 times I ran into name collision, it was to do withanyhow::Context
.Drawbacks
Editors do not support this right now, implying that we need a
cargo fix
for this to be useful.Example
Could be written as:
The text was updated successfully, but these errors were encountered: