Skip to content

Commit c237971

Browse files
committed
resolve: Tweak overwriting with ambiguous globs
Do not overwrite unless necessary, and combine both globs instead of losing the first one.
1 parent 227e7bd commit c237971

3 files changed

Lines changed: 15 additions & 16 deletions

File tree

compiler/rustc_resolve/src/imports.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
384384
// We are glob-importing the same item but with greater visibility.
385385
old_glob_decl.vis.set_unchecked(glob_decl.vis());
386386
old_glob_decl
387-
} else if glob_decl.is_ambiguity_recursive() {
388-
// Overwriting with an ambiguous glob import.
389-
glob_decl.warn_ambiguity.set_unchecked(true);
390-
glob_decl
387+
} else if glob_decl.is_ambiguity_recursive() && !old_glob_decl.is_ambiguity_recursive() {
388+
// Overwriting a non-ambiguous glob import with an ambiguous glob import.
389+
self.new_decl_with_ambiguity(old_glob_decl, glob_decl, true)
391390
} else {
392391
old_glob_decl
393392
}

tests/ui/imports/ambiguous-14.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ LL | g::foo();
88
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
99
= note: ambiguous because of multiple glob imports of a name in the same module
1010
note: `foo` could refer to the function imported here
11-
--> $DIR/ambiguous-14.rs:13:13
11+
--> $DIR/ambiguous-14.rs:18:13
1212
|
1313
LL | pub use a::*;
1414
| ^^^^
1515
= help: consider adding an explicit import of `foo` to disambiguate
1616
note: `foo` could also refer to the function imported here
17-
--> $DIR/ambiguous-14.rs:14:13
17+
--> $DIR/ambiguous-14.rs:19:13
1818
|
19-
LL | pub use b::*;
19+
LL | pub use f::*;
2020
| ^^^^
2121
= help: consider adding an explicit import of `foo` to disambiguate
2222
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
@@ -34,15 +34,15 @@ LL | g::foo();
3434
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
3535
= note: ambiguous because of multiple glob imports of a name in the same module
3636
note: `foo` could refer to the function imported here
37-
--> $DIR/ambiguous-14.rs:13:13
37+
--> $DIR/ambiguous-14.rs:18:13
3838
|
3939
LL | pub use a::*;
4040
| ^^^^
4141
= help: consider adding an explicit import of `foo` to disambiguate
4242
note: `foo` could also refer to the function imported here
43-
--> $DIR/ambiguous-14.rs:14:13
43+
--> $DIR/ambiguous-14.rs:19:13
4444
|
45-
LL | pub use b::*;
45+
LL | pub use f::*;
4646
| ^^^^
4747
= help: consider adding an explicit import of `foo` to disambiguate
4848
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default

tests/ui/imports/duplicate.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ LL | g::foo();
7878
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
7979
= note: ambiguous because of multiple glob imports of a name in the same module
8080
note: `foo` could refer to the function imported here
81-
--> $DIR/duplicate.rs:24:13
81+
--> $DIR/duplicate.rs:29:13
8282
|
8383
LL | pub use crate::a::*;
8484
| ^^^^^^^^^^^
8585
= help: consider adding an explicit import of `foo` to disambiguate
8686
note: `foo` could also refer to the function imported here
87-
--> $DIR/duplicate.rs:25:13
87+
--> $DIR/duplicate.rs:30:13
8888
|
89-
LL | pub use crate::b::*;
89+
LL | pub use crate::f::*;
9090
| ^^^^^^^^^^^
9191
= help: consider adding an explicit import of `foo` to disambiguate
9292
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
@@ -106,15 +106,15 @@ LL | g::foo();
106106
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
107107
= note: ambiguous because of multiple glob imports of a name in the same module
108108
note: `foo` could refer to the function imported here
109-
--> $DIR/duplicate.rs:24:13
109+
--> $DIR/duplicate.rs:29:13
110110
|
111111
LL | pub use crate::a::*;
112112
| ^^^^^^^^^^^
113113
= help: consider adding an explicit import of `foo` to disambiguate
114114
note: `foo` could also refer to the function imported here
115-
--> $DIR/duplicate.rs:25:13
115+
--> $DIR/duplicate.rs:30:13
116116
|
117-
LL | pub use crate::b::*;
117+
LL | pub use crate::f::*;
118118
| ^^^^^^^^^^^
119119
= help: consider adding an explicit import of `foo` to disambiguate
120120
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default

0 commit comments

Comments
 (0)