Skip to content

Commit 2278ef2

Browse files
Auto merge of #145108 - LorrensP-2158466:batched-import-resolution, r=<try>
Resolver: Batched Import Resolution
2 parents 0b278a5 + 8f39eee commit 2278ef2

14 files changed

+303
-255
lines changed

compiler/rustc_resolve/src/imports.rs

Lines changed: 219 additions & 130 deletions
Large diffs are not rendered by default.

compiler/rustc_resolve/src/lib.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,15 +1841,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
18411841
f(self, MacroNS);
18421842
}
18431843

1844-
fn per_ns_cm<'r, F: FnMut(&mut CmResolver<'r, 'ra, 'tcx>, Namespace)>(
1845-
mut self: CmResolver<'r, 'ra, 'tcx>,
1846-
mut f: F,
1847-
) {
1848-
f(&mut self, TypeNS);
1849-
f(&mut self, ValueNS);
1850-
f(&mut self, MacroNS);
1851-
}
1852-
18531844
fn is_builtin_macro(&self, res: Res) -> bool {
18541845
self.get_macro(res).is_some_and(|macro_data| macro_data.ext.builtin_name.is_some())
18551846
}
@@ -2567,12 +2558,6 @@ mod ref_mut {
25672558
true => self.p,
25682559
}
25692560
}
2570-
2571-
/// Returns a mutable reference to the inner value without checking if
2572-
/// it's in a mutable state.
2573-
pub(crate) fn get_mut_unchecked(&mut self) -> &mut T {
2574-
self.p
2575-
}
25762561
}
25772562

25782563
/// A wrapper around a [`Cell`] that only allows mutation based on a condition in the resolver.
@@ -2611,6 +2596,13 @@ mod ref_mut {
26112596
CmCell(Cell::new(value))
26122597
}
26132598

2599+
pub(crate) fn set<'ra, 'tcx>(&self, val: T, r: &Resolver<'ra, 'tcx>) {
2600+
if r.assert_speculative {
2601+
panic!()
2602+
}
2603+
self.0.set(val);
2604+
}
2605+
26142606
pub(crate) fn set_unchecked(&self, val: T) {
26152607
self.0.set(val);
26162608
}

tests/ui/imports/ambiguous-9.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ pub mod dsl {
44
mod range {
55
pub fn date_range() {}
66
}
7-
pub use self::range::*; //~ WARNING ambiguous glob re-exports
7+
pub use self::range::*;
88
use super::prelude::*;
99
}
1010

1111
pub mod prelude {
1212
mod t {
1313
pub fn date_range() {}
1414
}
15-
pub use self::t::*; //~ WARNING ambiguous glob re-exports
16-
pub use super::dsl::*;
15+
pub use self::t::*;
16+
pub use super::dsl::*; //~ WARNING ambiguous glob re-exports
1717
}
1818

1919
use dsl::*;
@@ -23,6 +23,4 @@ fn main() {
2323
date_range();
2424
//~^ ERROR `date_range` is ambiguous
2525
//~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
26-
//~| ERROR `date_range` is ambiguous
27-
//~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2826
}
Lines changed: 17 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
warning: ambiguous glob re-exports
2-
--> $DIR/ambiguous-9.rs:7:13
2+
--> $DIR/ambiguous-9.rs:16:13
33
|
4-
LL | pub use self::range::*;
5-
| ^^^^^^^^^^^^^^ the name `date_range` in the value namespace is first re-exported here
6-
LL | use super::prelude::*;
7-
| ----------------- but the name `date_range` in the value namespace is also re-exported here
4+
LL | pub use self::t::*;
5+
| ---------- but the name `date_range` in the value namespace is also re-exported here
6+
LL | pub use super::dsl::*;
7+
| ^^^^^^^^^^^^^ the name `date_range` in the value namespace is first re-exported here
88
|
99
= note: `#[warn(ambiguous_glob_reexports)]` on by default
1010

@@ -18,50 +18,20 @@ LL | date_range();
1818
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
1919
= note: ambiguous because of multiple glob imports of a name in the same module
2020
note: `date_range` could refer to the function imported here
21-
--> $DIR/ambiguous-9.rs:7:13
21+
--> $DIR/ambiguous-9.rs:16:13
2222
|
23-
LL | pub use self::range::*;
24-
| ^^^^^^^^^^^^^^
23+
LL | pub use super::dsl::*;
24+
| ^^^^^^^^^^^^^
2525
= help: consider adding an explicit import of `date_range` to disambiguate
2626
note: `date_range` could also refer to the function imported here
27-
--> $DIR/ambiguous-9.rs:8:9
28-
|
29-
LL | use super::prelude::*;
30-
| ^^^^^^^^^^^^^^^^^
31-
= help: consider adding an explicit import of `date_range` to disambiguate
32-
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
33-
34-
warning: ambiguous glob re-exports
3527
--> $DIR/ambiguous-9.rs:15:13
3628
|
3729
LL | pub use self::t::*;
38-
| ^^^^^^^^^^ the name `date_range` in the value namespace is first re-exported here
39-
LL | pub use super::dsl::*;
40-
| ------------- but the name `date_range` in the value namespace is also re-exported here
41-
42-
error: `date_range` is ambiguous
43-
--> $DIR/ambiguous-9.rs:23:5
44-
|
45-
LL | date_range();
46-
| ^^^^^^^^^^ ambiguous name
47-
|
48-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
49-
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
50-
= note: ambiguous because of multiple glob imports of a name in the same module
51-
note: `date_range` could refer to the function imported here
52-
--> $DIR/ambiguous-9.rs:19:5
53-
|
54-
LL | use dsl::*;
55-
| ^^^^^^
56-
= help: consider adding an explicit import of `date_range` to disambiguate
57-
note: `date_range` could also refer to the function imported here
58-
--> $DIR/ambiguous-9.rs:20:5
59-
|
60-
LL | use prelude::*;
61-
| ^^^^^^^^^^
30+
| ^^^^^^^^^^
6231
= help: consider adding an explicit import of `date_range` to disambiguate
32+
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
6333

64-
error: aborting due to 2 previous errors; 2 warnings emitted
34+
error: aborting due to 1 previous error; 1 warning emitted
6535

6636
Future incompatibility report: Future breakage diagnostic:
6737
error: `date_range` is ambiguous
@@ -74,40 +44,16 @@ LL | date_range();
7444
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
7545
= note: ambiguous because of multiple glob imports of a name in the same module
7646
note: `date_range` could refer to the function imported here
77-
--> $DIR/ambiguous-9.rs:7:13
78-
|
79-
LL | pub use self::range::*;
80-
| ^^^^^^^^^^^^^^
81-
= help: consider adding an explicit import of `date_range` to disambiguate
82-
note: `date_range` could also refer to the function imported here
83-
--> $DIR/ambiguous-9.rs:8:9
84-
|
85-
LL | use super::prelude::*;
86-
| ^^^^^^^^^^^^^^^^^
87-
= help: consider adding an explicit import of `date_range` to disambiguate
88-
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
89-
90-
Future breakage diagnostic:
91-
error: `date_range` is ambiguous
92-
--> $DIR/ambiguous-9.rs:23:5
93-
|
94-
LL | date_range();
95-
| ^^^^^^^^^^ ambiguous name
96-
|
97-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
98-
= 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
100-
note: `date_range` could refer to the function imported here
101-
--> $DIR/ambiguous-9.rs:19:5
47+
--> $DIR/ambiguous-9.rs:16:13
10248
|
103-
LL | use dsl::*;
104-
| ^^^^^^
49+
LL | pub use super::dsl::*;
50+
| ^^^^^^^^^^^^^
10551
= help: consider adding an explicit import of `date_range` to disambiguate
10652
note: `date_range` could also refer to the function imported here
107-
--> $DIR/ambiguous-9.rs:20:5
53+
--> $DIR/ambiguous-9.rs:15:13
10854
|
109-
LL | use prelude::*;
110-
| ^^^^^^^^^^
55+
LL | pub use self::t::*;
56+
| ^^^^^^^^^^
11157
= help: consider adding an explicit import of `date_range` to disambiguate
11258
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
11359

tests/ui/imports/glob-conflict-cross-crate-1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn main() {
66
glob_conflict::f(); //~ ERROR cannot find function `f` in crate `glob_conflict`
77
//^ FIXME: `glob_conflict::f` should raise an
88
// ambiguity error instead of a not found error.
9-
glob_conflict::glob::f(); //~ ERROR cannot find function `f` in module `glob_conflict::glob`
9+
glob_conflict::glob::f();
1010
//^ FIXME: `glob_conflict::glob::f` should raise an
1111
// ambiguity error instead of a not found error.
1212
}

tests/ui/imports/glob-conflict-cross-crate-1.stderr

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ error[E0425]: cannot find function `f` in crate `glob_conflict`
33
|
44
LL | glob_conflict::f();
55
| ^ not found in `glob_conflict`
6-
7-
error[E0425]: cannot find function `f` in module `glob_conflict::glob`
8-
--> $DIR/glob-conflict-cross-crate-1.rs:9:26
96
|
10-
LL | glob_conflict::glob::f();
11-
| ^ not found in `glob_conflict::glob`
7+
help: consider importing this function
8+
|
9+
LL + use glob_conflict::glob::f;
10+
|
11+
help: if you import `f`, refer to it directly
12+
|
13+
LL - glob_conflict::f();
14+
LL + f();
15+
|
1216

13-
error: aborting due to 2 previous errors
17+
error: aborting due to 1 previous error
1418

1519
For more information about this error, try `rustc --explain E0425`.

tests/ui/imports/import-loop-2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
mod a {
2-
pub use crate::b::x;
2+
pub use crate::b::x; //~ ERROR unresolved import `crate::b::x`
33
}
44

55
mod b {
6-
pub use crate::a::x; //~ ERROR unresolved import `crate::a::x`
6+
pub use crate::a::x;
77

88
fn main() { let y = x; }
99
}

tests/ui/imports/import-loop-2.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0432]: unresolved import `crate::a::x`
2-
--> $DIR/import-loop-2.rs:6:13
1+
error[E0432]: unresolved import `crate::b::x`
2+
--> $DIR/import-loop-2.rs:2:13
33
|
4-
LL | pub use crate::a::x;
5-
| ^^^^^^^^^^^ no `x` in `a`
4+
LL | pub use crate::b::x;
5+
| ^^^^^^^^^^^ no `x` in `b`
66

77
error: aborting due to 1 previous error
88

tests/ui/imports/import4.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mod a { pub use crate::b::foo; }
2-
mod b { pub use crate::a::foo; } //~ ERROR unresolved import `crate::a::foo`
1+
mod a { pub use crate::b::foo; } //~ ERROR unresolved import `crate::b::foo`
2+
mod b { pub use crate::a::foo; }
33

44
fn main() { println!("loop"); }

tests/ui/imports/import4.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0432]: unresolved import `crate::a::foo`
2-
--> $DIR/import4.rs:2:17
1+
error[E0432]: unresolved import `crate::b::foo`
2+
--> $DIR/import4.rs:1:17
33
|
4-
LL | mod b { pub use crate::a::foo; }
5-
| ^^^^^^^^^^^^^ no `foo` in `a`
4+
LL | mod a { pub use crate::b::foo; }
5+
| ^^^^^^^^^^^^^ no `foo` in `b`
66

77
error: aborting due to 1 previous error
88

0 commit comments

Comments
 (0)