Skip to content

Tracking Issue for ambiguous_glob_imports lint #114095

Open
@bvanjoi

Description

@bvanjoi

This is a tracking issue for the "ambiguous_glob_imports", a lint that follows the breaking change policy.

Problem

The name resolution algorithm in rustc does not update bindings recursively when the (Module, Key) already has a binding. This can result in a situation where a glob binding should be marked as ambiguous but it is not, potentially causing code that should fail to compile to pass instead.

For example(#112713):

pub fn foo() -> u32 {
    use sub::*;
    C
}

mod sub {
    mod mod1 { pub const C: u32 = 1; }
    mod mod2 { pub const C: u32 = 2; }

    pub use mod1::*;
    pub use mod2::*;
}

The C in foo function was referred to (Mod(root), Key(C)), where it should have an ambiguous binding but actually not due to the stop the update process early.

Here are additional details regarding the update process:

- importer resolve_glob_import
0 use sub::* nothing was defined
1 use mod1::* 1. (root::sub, C) -> root::sub::mod1::C without ambiguity;
2. (root, C) -> root::sub::mod1::C without ambiguity.
2 use mod2::* 1. (root::sub, C) -> root::sub::mod1::C with ambiguity;
2. It had been stop update the binding of (root, C) due to (root, C) already has a binding.

Solve

We have relaxed the condition for update process and now treat the updated ambiguous error as a warning instead of an error. We use the ambigous_glob_imports lint for back compatibility.

Steps

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-future-incompatibilityCategory: Future-incompatibility lintsC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions