Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bayov opened this issue Jan 2, 2024 · 2 comments · Fixed by #13322
Closed

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

bayov opened this issue Jan 2, 2024 · 2 comments · Fixed by #13322
Labels
A-lint Area: New lints

Comments

@bayov
Copy link

bayov commented Jan 2, 2024

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');
}
@jrose-signal
Copy link

Same as #11969 ?

@bayov
Copy link
Author

bayov commented Jan 25, 2024

Yep, this is a duplicate it seems,

@y21 y21 linked a pull request Sep 2, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants