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

Lint against single-element use paths in 2018 edition #61640

Closed
cramertj opened this issue Jun 7, 2019 · 4 comments
Closed

Lint against single-element use paths in 2018 edition #61640

cramertj opened this issue Jun 7, 2019 · 4 comments
Labels
A-edition-2018-lints Area: lints supporting the 2018 edition A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-resolve Area: Path resolution C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@cramertj
Copy link
Member

cramertj commented Jun 7, 2019

I wind up leaving a lot of code review comments about not writing things like use std; or use some_extern_crate; in 2018 edition.

@jonas-schievink jonas-schievink added A-edition-2018-lints Area: lints supporting the 2018 edition A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-resolve Area: Path resolution C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jun 7, 2019
@Centril Centril added T-lang Relevant to the language team, which will review and decide on the PR/issue. I-nominated labels Jun 7, 2019
@petrochenkov
Copy link
Contributor

This is an extension of the "redundant import" lint implemented in #58805.

Right now it covers imports in blocks

fn main() {
    use std; // warning: the item `std` is imported redundantly
}

but not in modules (due to some complexities described in #10178 (comment)).

@Centril Centril added C-bug Category: This is a bug. and removed C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jun 20, 2019
@joshtriplett
Copy link
Member

We discussed this in the @rust-lang/lang meeting. We agreed that 1) there should be a lint for this, and 2) ideally it should be a fixed version of the redundant import lint.

@kpreid
Copy link
Contributor

kpreid commented May 26, 2022

This would be a good lint to have because many beginners speculate that use foo; brings foo into scope, as opposed to the actual situation that use foo::bar; brings bar into scope given that foo already is in scope. In my opinion, it would be best if

  • The lint has help that specifically explains that 1-element paths in use usually do nothing and are only useful in special cases (pub use, as).
  • The lint is deny-by-default in a future edition, because it indicates a misunderstanding of the module/crate/path system which is likely to result in follow-up errors (such as if they assume that use foo; works like use foo::*;), so the user should be promptly told “this won't help”. (Many beginners will completely ignore warnings while trying to fix an error.)

@petrochenkov
Copy link
Contributor

This was implemented in #117772.
There was a large ecosystem fallout though, so #121708 now discusses how to release this change better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2018-lints Area: lints supporting the 2018 edition A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-resolve Area: Path resolution C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants