Skip to content

Commit 1fe68dc

Browse files
address simple requests from reviewer
1 parent 9c91fb1 commit 1fe68dc

10 files changed

+34
-48
lines changed

compiler/rustc_resolve/src/imports.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_span::edit_distance::find_best_match_for_name;
2222
use rustc_span::hygiene::LocalExpnId;
2323
use rustc_span::{Ident, Span, Symbol, kw, sym};
2424
use smallvec::SmallVec;
25-
use tracing::{debug, instrument};
25+
use tracing::debug;
2626

2727
use crate::Determinacy::{self, *};
2828
use crate::Namespace::*;
@@ -242,8 +242,9 @@ pub(crate) struct NameResolution<'ra> {
242242
/// Single imports that may define the name in the namespace.
243243
/// Imports are arena-allocated, so it's ok to use pointers as keys.
244244
pub single_imports: FxIndexSet<Import<'ra>>,
245-
/// The least shadowable known non-glob binding for this name, or None if there are no known bindings.
245+
/// The non-glob binding for this name, if it is known to exist.
246246
pub non_glob_binding: Option<NameBinding<'ra>>,
247+
/// The glob binding for this name, if it is known to exist.
247248
pub glob_binding: Option<NameBinding<'ra>>,
248249
}
249250

@@ -255,7 +256,7 @@ impl<'ra> NameResolution<'ra> {
255256
}
256257

257258
pub(crate) fn late_binding(&self) -> Option<NameBinding<'ra>> {
258-
self.non_glob_binding.or_else(|| self.glob_binding)
259+
self.non_glob_binding.or(self.glob_binding)
259260
}
260261
}
261262

@@ -621,15 +622,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
621622
}
622623
}
623624

624-
#[instrument(skip(self), level = "debug")]
625625
pub(crate) fn check_hidden_glob_reexports(
626626
&mut self,
627627
exported_ambiguities: FxHashSet<NameBinding<'ra>>,
628628
) {
629629
for module in self.arenas.local_modules().iter() {
630630
for (key, resolution) in self.resolutions(*module).borrow().iter() {
631631
let resolution = resolution.borrow();
632-
debug!(?resolution);
633632

634633
let Some(binding) = resolution.late_binding() else { continue };
635634

compiler/rustc_resolve/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,7 @@ impl<'ra> Module<'ra> {
641641
F: FnMut(&mut R, Ident, Namespace, NameBinding<'ra>),
642642
{
643643
for (key, name_resolution) in resolver.as_mut().resolutions(self).borrow().iter() {
644-
let resolution = name_resolution.borrow();
645-
if let Some(binding) = resolution.non_glob_binding.or_else(|| resolution.glob_binding) {
644+
if let Some(binding) = name_resolution.borrow().late_binding() {
646645
f(resolver, key.ident, key.ns, binding);
647646
}
648647
}

tests/ui/imports/ambiguous-17.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// https://github.com/rust-lang/rust/pull/113099#issuecomment-1638206152
22

3-
pub use evp::*;
4-
//~^ WARNING ambiguous glob re-exports
3+
pub use evp::*; //~ WARNING ambiguous glob re-exports
54
pub use handwritten::*;
65

76
macro_rules! m {

tests/ui/imports/ambiguous-17.stderr

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ warning: ambiguous glob re-exports
33
|
44
LL | pub use evp::*;
55
| ^^^^^^ the name `id` in the value namespace is first re-exported here
6-
LL |
76
LL | pub use handwritten::*;
87
| -------------- but the name `id` in the value namespace is also re-exported here
98
|
109
= note: `#[warn(ambiguous_glob_reexports)]` on by default
1110

1211
error: `id` is ambiguous
13-
--> $DIR/ambiguous-17.rs:26:5
12+
--> $DIR/ambiguous-17.rs:25:5
1413
|
1514
LL | id();
1615
| ^^ ambiguous name
@@ -25,7 +24,7 @@ LL | pub use evp::*;
2524
| ^^^^^^
2625
= help: consider adding an explicit import of `id` to disambiguate
2726
note: `id` could also refer to the function imported here
28-
--> $DIR/ambiguous-17.rs:5:9
27+
--> $DIR/ambiguous-17.rs:4:9
2928
|
3029
LL | pub use handwritten::*;
3130
| ^^^^^^^^^^^^^^
@@ -36,7 +35,7 @@ error: aborting due to 1 previous error; 1 warning emitted
3635

3736
Future incompatibility report: Future breakage diagnostic:
3837
error: `id` is ambiguous
39-
--> $DIR/ambiguous-17.rs:26:5
38+
--> $DIR/ambiguous-17.rs:25:5
4039
|
4140
LL | id();
4241
| ^^ ambiguous name
@@ -51,7 +50,7 @@ LL | pub use evp::*;
5150
| ^^^^^^
5251
= help: consider adding an explicit import of `id` to disambiguate
5352
note: `id` could also refer to the function imported here
54-
--> $DIR/ambiguous-17.rs:5:9
53+
--> $DIR/ambiguous-17.rs:4:9
5554
|
5655
LL | pub use handwritten::*;
5756
| ^^^^^^^^^^^^^^

tests/ui/imports/ambiguous-4-extern.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ macro_rules! m {
99
};
1010
}
1111

12-
pub use evp::*;
13-
//~^ WARNING ambiguous glob re-exports
12+
pub use evp::*; //~ WARNING ambiguous glob re-exports
1413
pub use handwritten::*;
1514

1615
mod evp {

tests/ui/imports/ambiguous-4-extern.stderr

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ warning: ambiguous glob re-exports
33
|
44
LL | pub use evp::*;
55
| ^^^^^^ the name `id` in the value namespace is first re-exported here
6-
LL |
76
LL | pub use handwritten::*;
87
| -------------- but the name `id` in the value namespace is also re-exported here
98
|
109
= note: `#[warn(ambiguous_glob_reexports)]` on by default
1110

1211
warning: `id` is ambiguous
13-
--> $DIR/ambiguous-4-extern.rs:26:5
12+
--> $DIR/ambiguous-4-extern.rs:25:5
1413
|
1514
LL | id();
1615
| ^^ ambiguous name
@@ -25,7 +24,7 @@ LL | pub use evp::*;
2524
| ^^^^^^
2625
= help: consider adding an explicit import of `id` to disambiguate
2726
note: `id` could also refer to the function imported here
28-
--> $DIR/ambiguous-4-extern.rs:14:9
27+
--> $DIR/ambiguous-4-extern.rs:13:9
2928
|
3029
LL | pub use handwritten::*;
3130
| ^^^^^^^^^^^^^^
@@ -40,7 +39,7 @@ warning: 2 warnings emitted
4039

4140
Future incompatibility report: Future breakage diagnostic:
4241
warning: `id` is ambiguous
43-
--> $DIR/ambiguous-4-extern.rs:26:5
42+
--> $DIR/ambiguous-4-extern.rs:25:5
4443
|
4544
LL | id();
4645
| ^^ ambiguous name
@@ -55,7 +54,7 @@ LL | pub use evp::*;
5554
| ^^^^^^
5655
= help: consider adding an explicit import of `id` to disambiguate
5756
note: `id` could also refer to the function imported here
58-
--> $DIR/ambiguous-4-extern.rs:14:9
57+
--> $DIR/ambiguous-4-extern.rs:13:9
5958
|
6059
LL | pub use handwritten::*;
6160
| ^^^^^^^^^^^^^^

tests/ui/imports/ambiguous-9.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@ pub mod dsl {
44
mod range {
55
pub fn date_range() {}
66
}
7-
pub use self::range::*;
8-
//~^ WARNING ambiguous glob re-exports
7+
pub use self::range::*; //~ WARNING ambiguous glob re-exports
98
use super::prelude::*;
109
}
1110

1211
pub mod prelude {
1312
mod t {
1413
pub fn date_range() {}
1514
}
16-
pub use self::t::*;
17-
//~^ WARNING ambiguous glob re-exports
15+
pub use self::t::*; //~ WARNING ambiguous glob re-exports
1816
pub use super::dsl::*;
1917
}
2018

tests/ui/imports/ambiguous-9.stderr

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ warning: ambiguous glob re-exports
33
|
44
LL | pub use self::range::*;
55
| ^^^^^^^^^^^^^^ the name `date_range` in the value namespace is first re-exported here
6-
LL |
76
LL | use super::prelude::*;
87
| ----------------- but the name `date_range` in the value namespace is also re-exported here
98
|
109
= note: `#[warn(ambiguous_glob_reexports)]` on by default
1110

1211
error: `date_range` is ambiguous
13-
--> $DIR/ambiguous-9.rs:25:5
12+
--> $DIR/ambiguous-9.rs:23:5
1413
|
1514
LL | date_range();
1615
| ^^^^^^^^^^ ambiguous name
@@ -25,24 +24,23 @@ LL | pub use self::range::*;
2524
| ^^^^^^^^^^^^^^
2625
= help: consider adding an explicit import of `date_range` to disambiguate
2726
note: `date_range` could also refer to the function imported here
28-
--> $DIR/ambiguous-9.rs:9:9
27+
--> $DIR/ambiguous-9.rs:8:9
2928
|
3029
LL | use super::prelude::*;
3130
| ^^^^^^^^^^^^^^^^^
3231
= help: consider adding an explicit import of `date_range` to disambiguate
3332
= note: `#[deny(ambiguous_glob_imports)]` on by default
3433

3534
warning: ambiguous glob re-exports
36-
--> $DIR/ambiguous-9.rs:16:13
35+
--> $DIR/ambiguous-9.rs:15:13
3736
|
3837
LL | pub use self::t::*;
3938
| ^^^^^^^^^^ the name `date_range` in the value namespace is first re-exported here
40-
LL |
4139
LL | pub use super::dsl::*;
4240
| ------------- but the name `date_range` in the value namespace is also re-exported here
4341

4442
error: `date_range` is ambiguous
45-
--> $DIR/ambiguous-9.rs:25:5
43+
--> $DIR/ambiguous-9.rs:23:5
4644
|
4745
LL | date_range();
4846
| ^^^^^^^^^^ ambiguous name
@@ -51,13 +49,13 @@ LL | date_range();
5149
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
5250
= note: ambiguous because of multiple glob imports of a name in the same module
5351
note: `date_range` could refer to the function imported here
54-
--> $DIR/ambiguous-9.rs:21:5
52+
--> $DIR/ambiguous-9.rs:19:5
5553
|
5654
LL | use dsl::*;
5755
| ^^^^^^
5856
= help: consider adding an explicit import of `date_range` to disambiguate
5957
note: `date_range` could also refer to the function imported here
60-
--> $DIR/ambiguous-9.rs:22:5
58+
--> $DIR/ambiguous-9.rs:20:5
6159
|
6260
LL | use prelude::*;
6361
| ^^^^^^^^^^
@@ -67,7 +65,7 @@ error: aborting due to 2 previous errors; 2 warnings emitted
6765

6866
Future incompatibility report: Future breakage diagnostic:
6967
error: `date_range` is ambiguous
70-
--> $DIR/ambiguous-9.rs:25:5
68+
--> $DIR/ambiguous-9.rs:23:5
7169
|
7270
LL | date_range();
7371
| ^^^^^^^^^^ ambiguous name
@@ -82,7 +80,7 @@ LL | pub use self::range::*;
8280
| ^^^^^^^^^^^^^^
8381
= help: consider adding an explicit import of `date_range` to disambiguate
8482
note: `date_range` could also refer to the function imported here
85-
--> $DIR/ambiguous-9.rs:9:9
83+
--> $DIR/ambiguous-9.rs:8:9
8684
|
8785
LL | use super::prelude::*;
8886
| ^^^^^^^^^^^^^^^^^
@@ -91,7 +89,7 @@ LL | use super::prelude::*;
9189

9290
Future breakage diagnostic:
9391
error: `date_range` is ambiguous
94-
--> $DIR/ambiguous-9.rs:25:5
92+
--> $DIR/ambiguous-9.rs:23:5
9593
|
9694
LL | date_range();
9795
| ^^^^^^^^^^ ambiguous name
@@ -100,13 +98,13 @@ LL | date_range();
10098
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
10199
= note: ambiguous because of multiple glob imports of a name in the same module
102100
note: `date_range` could refer to the function imported here
103-
--> $DIR/ambiguous-9.rs:21:5
101+
--> $DIR/ambiguous-9.rs:19:5
104102
|
105103
LL | use dsl::*;
106104
| ^^^^^^
107105
= help: consider adding an explicit import of `date_range` to disambiguate
108106
note: `date_range` could also refer to the function imported here
109-
--> $DIR/ambiguous-9.rs:22:5
107+
--> $DIR/ambiguous-9.rs:20:5
110108
|
111109
LL | use prelude::*;
112110
| ^^^^^^^^^^

tests/ui/resolve/issue-107563-ambiguous-glob-reexports.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@ pub use foo::*;
1414
pub use bar::*;
1515

1616
mod ambiguous {
17-
mod m1 {
18-
pub type A = u8;
19-
}
20-
mod m2 {
21-
pub type A = u8;
22-
}
17+
mod m1 { pub type A = u8; }
18+
mod m2 { pub type A = u8; }
2319
pub use self::m1::*;
2420
//~^ ERROR ambiguous glob re-exports
2521
pub use self::m2::*;

tests/ui/resolve/issue-107563-ambiguous-glob-reexports.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
error[E0659]: `A` is ambiguous
2-
--> $DIR/issue-107563-ambiguous-glob-reexports.rs:29:24
2+
--> $DIR/issue-107563-ambiguous-glob-reexports.rs:25:24
33
|
44
LL | pub use ambiguous::A;
55
| ^ ambiguous name
66
|
77
= note: ambiguous because of multiple glob imports of a name in the same module
88
note: `A` could refer to the type alias imported here
9-
--> $DIR/issue-107563-ambiguous-glob-reexports.rs:23:13
9+
--> $DIR/issue-107563-ambiguous-glob-reexports.rs:19:13
1010
|
1111
LL | pub use self::m1::*;
1212
| ^^^^^^^^^^^
1313
= help: consider adding an explicit import of `A` to disambiguate
1414
note: `A` could also refer to the type alias imported here
15-
--> $DIR/issue-107563-ambiguous-glob-reexports.rs:25:13
15+
--> $DIR/issue-107563-ambiguous-glob-reexports.rs:21:13
1616
|
1717
LL | pub use self::m2::*;
1818
| ^^^^^^^^^^^
@@ -34,7 +34,7 @@ LL | #![deny(ambiguous_glob_reexports)]
3434
| ^^^^^^^^^^^^^^^^^^^^^^^^
3535

3636
error: ambiguous glob re-exports
37-
--> $DIR/issue-107563-ambiguous-glob-reexports.rs:23:13
37+
--> $DIR/issue-107563-ambiguous-glob-reexports.rs:19:13
3838
|
3939
LL | pub use self::m1::*;
4040
| ^^^^^^^^^^^ the name `A` in the type namespace is first re-exported here

0 commit comments

Comments
 (0)