Skip to content

Suggest use ... as _ when importing traits only #11969

Closed
@nyurik

Description

@nyurik

What it does

When importing names that are not used directly, but used as a trait, I think it is better to use the as _ clause to avoid polluting current scope with unused names.

Advantage

  • does not introduce unused names into the current scope
  • fewer potential "got-chas"

Drawbacks

No response

Example

// the `Write` here is never actually used
use std::fmt::Write;

fn main() {
    let mut s = String::new();
    let _ = write!(s, "hello, world!");
    println!("{s}");
}

Could be written as:

use std::fmt::Write as _;

...

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions