Skip to content

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

Closed
@cramertj

Description

@cramertj
Member

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.

Activity

added
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
A-resolveArea: Name/path resolution done by `rustc_resolve` specifically
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
on Jun 7, 2019
petrochenkov

petrochenkov commented on Jun 8, 2019

@petrochenkov
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)).

added
C-bugCategory: This is a bug.
and removed
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
on Jun 20, 2019
joshtriplett

joshtriplett commented on Jun 20, 2019

@joshtriplett
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

kpreid commented on May 26, 2022

@kpreid
Contributor

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

petrochenkov commented on Mar 2, 2024

@petrochenkov
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-edition-2018Area: The 2018 editionA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @joshtriplett@kpreid@Centril@jonas-schievink@petrochenkov

        Issue actions

          Lint against single-element `use` paths in 2018 edition · Issue #61640 · rust-lang/rust