Skip to content

Change "A non-empty glob must import something with the glob's visibility" to be a lint? #62334

Description

@fpoli

Consider the following three examples: A and C are accepted and B has a compilation error. However, the message reported in B looks more like a lint than a compilation error.

A consequence of this error is that adding a non-public function to a module (e.g. the bar in B) may break code that imports from that module. This causes surprises when refactoring.

Shouldn't "A non-empty glob must import something with the glob's visibility" be a lint?

The original discussion is here: https://users.rust-lang.org/t/a-non-empty-glob-must-import-something-with-the-globs-visibility-uhhh-okay-but-why

A

pub use self::a::*;
mod a {
    fn foo() {}
}

B

// ERROR: A non-empty glob must import something with the glob's visibility
pub use self::b::*;
mod b {
    fn foo() {}
    pub(super) fn bar() {}
}

C

// okay: there's a pub item
pub use self::c::*;
mod c {
    fn foo() {}
    pub(super) fn bar() {}
    pub fn baz() {}
}

Activity

  1. petrochenkov commented on Jul 3, 2019

    @petrochenkov
    Contributor

    The error was introduced in #35894 as a part of import modularization, and discussed in one of the related issues, but I can't find where exactly.

    The error was introduced by analogy with errors for single imports (and just to be conservative):

    mod m {
        fn f() {}
    }
    
    use m::f; // Doesn't import anything and therefore reports an error.
    use m::g; // Doesn't import anything and therefore reports an error.
    use m::*; // Doesn't import anything and therefore reports an error.

    The error is not technically necessary, and we should be able to report it as a lint for glob imports while keeping it an error for single imports.

  2. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    A-resolveArea: Name/path resolution done by `rustc_resolve` specifically
    T-langRelevant to the language team
    on Jul 28, 2019
  3. fpoli commented on Aug 28, 2019

    @fpoli
    ContributorAuthor

    Would this be a "good first issue" or is it complex to fix?

  4. petrochenkov commented on Aug 28, 2019

    @petrochenkov
    Contributor

    No, not complex.

    • Find where "non-empty glob must import something" is reported.
    • Replace span_err with buffer_lint(UNUSED_IMPORTS, ...).
  5. added
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
    on Oct 17, 2019
  6. traxys commented on Oct 18, 2019

    @traxys
    Contributor

    I want to do this issue but the problem I have is with a test (ui/imports/reexports) that checks for this error, I don't know the compiler structure so I don't know when compiling this file the lint will not be reported because of the other errors or not. Else I changed the span_err to buffer_lint

  7. added a commit that references this issue on Oct 29, 2019
    e6a00cf
  8. added a commit that references this issue on Oct 29, 2019
    0d755ff
  9. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    and removed
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    on Dec 21, 2024
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-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions