resolve: Tweak overwriting with ambiguous globs

Do not overwrite unless necessary, and combine both globs instead of losing the first one.
This commit is contained in:
Vadim Petrochenkov 2025-12-30 02:49:14 +03:00
parent 227e7bd48b
commit c2379717a2
3 changed files with 15 additions and 16 deletions

View file

@ -384,10 +384,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
// We are glob-importing the same item but with greater visibility.
old_glob_decl.vis.set_unchecked(glob_decl.vis());
old_glob_decl
} else if glob_decl.is_ambiguity_recursive() {
// Overwriting with an ambiguous glob import.
glob_decl.warn_ambiguity.set_unchecked(true);
glob_decl
} else if glob_decl.is_ambiguity_recursive() && !old_glob_decl.is_ambiguity_recursive() {
// Overwriting a non-ambiguous glob import with an ambiguous glob import.
self.new_decl_with_ambiguity(old_glob_decl, glob_decl, true)
} else {
old_glob_decl
}

View file

@ -8,15 +8,15 @@ LL | g::foo();
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
= note: ambiguous because of multiple glob imports of a name in the same module
note: `foo` could refer to the function imported here
--> $DIR/ambiguous-14.rs:13:13
--> $DIR/ambiguous-14.rs:18:13
|
LL | pub use a::*;
| ^^^^
= help: consider adding an explicit import of `foo` to disambiguate
note: `foo` could also refer to the function imported here
--> $DIR/ambiguous-14.rs:14:13
--> $DIR/ambiguous-14.rs:19:13
|
LL | pub use b::*;
LL | pub use f::*;
| ^^^^
= help: consider adding an explicit import of `foo` to disambiguate
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
@ -34,15 +34,15 @@ LL | g::foo();
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
= note: ambiguous because of multiple glob imports of a name in the same module
note: `foo` could refer to the function imported here
--> $DIR/ambiguous-14.rs:13:13
--> $DIR/ambiguous-14.rs:18:13
|
LL | pub use a::*;
| ^^^^
= help: consider adding an explicit import of `foo` to disambiguate
note: `foo` could also refer to the function imported here
--> $DIR/ambiguous-14.rs:14:13
--> $DIR/ambiguous-14.rs:19:13
|
LL | pub use b::*;
LL | pub use f::*;
| ^^^^
= help: consider adding an explicit import of `foo` to disambiguate
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default

View file

@ -78,15 +78,15 @@ LL | g::foo();
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
= note: ambiguous because of multiple glob imports of a name in the same module
note: `foo` could refer to the function imported here
--> $DIR/duplicate.rs:24:13
--> $DIR/duplicate.rs:29:13
|
LL | pub use crate::a::*;
| ^^^^^^^^^^^
= help: consider adding an explicit import of `foo` to disambiguate
note: `foo` could also refer to the function imported here
--> $DIR/duplicate.rs:25:13
--> $DIR/duplicate.rs:30:13
|
LL | pub use crate::b::*;
LL | pub use crate::f::*;
| ^^^^^^^^^^^
= help: consider adding an explicit import of `foo` to disambiguate
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
@ -106,15 +106,15 @@ LL | g::foo();
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
= note: ambiguous because of multiple glob imports of a name in the same module
note: `foo` could refer to the function imported here
--> $DIR/duplicate.rs:24:13
--> $DIR/duplicate.rs:29:13
|
LL | pub use crate::a::*;
| ^^^^^^^^^^^
= help: consider adding an explicit import of `foo` to disambiguate
note: `foo` could also refer to the function imported here
--> $DIR/duplicate.rs:25:13
--> $DIR/duplicate.rs:30:13
|
LL | pub use crate::b::*;
LL | pub use crate::f::*;
| ^^^^^^^^^^^
= help: consider adding an explicit import of `foo` to disambiguate
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default