Skip to content

Suggestion to anonymise trait imports that are not used directly #12072

Closed
@bayov

Description

@bayov

What it does

Changes trait imports that are not directly used to be anonymous.

Advantage

  • Removes unused identifiers from scope.
  • Clearly marks the intent of imports; seeing use std::fmt::Write as _ is an indicator that Write is only being used so that its trait methods are in scope, and not referred to directly.
  • Lowers chance of conflicts with similarly named traits.

Drawbacks

No response

Example

fn foo() {
    use std::fmt::Write;
    let mut s = String::new();
    s.write_char('x');
}

Could be written as:

fn foo() {
    use std::fmt::Write as _; // anonymous
    let mut s = String::new();
    s.write_char('x');
}

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