Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
355 changes: 234 additions & 121 deletions compiler/rustc_resolve/src/imports.rs

Large diffs are not rendered by default.

24 changes: 9 additions & 15 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,7 @@ pub struct Resolver<'ra, 'tcx> {
/// Crate-local macro expanded `macro_export` referred to by a module-relative path.
macro_expanded_macro_export_errors: BTreeSet<(Span, Span)> = BTreeSet::new(),

macro_vis_hack_map: FxIndexSet<(Module<'ra>, DefId)>,
/// When a type is re-exported that has an inaccessible constructor because it has fields that
/// are inaccessible from the import's scope, we mark that as the type won't be able to be built
/// through the re-export. We use this information to extend the existing diagnostic.
Expand Down Expand Up @@ -1621,6 +1622,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
glob_map: Default::default(),
used_imports: FxHashSet::default(),
maybe_unused_trait_imports: Default::default(),
macro_vis_hack_map: Default::default(),
inaccessible_ctor_reexport: Default::default(),

arenas,
Expand Down Expand Up @@ -1863,15 +1865,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
f(self, MacroNS);
}

fn per_ns_cm<'r, F: FnMut(&mut CmResolver<'r, 'ra, 'tcx>, Namespace)>(
mut self: CmResolver<'r, 'ra, 'tcx>,
mut f: F,
) {
f(&mut self, TypeNS);
f(&mut self, ValueNS);
f(&mut self, MacroNS);
}

fn is_builtin_macro(&self, res: Res) -> bool {
self.get_macro(res).is_some_and(|macro_data| macro_data.ext.builtin_name.is_some())
}
Expand Down Expand Up @@ -2607,12 +2600,6 @@ mod ref_mut {
true => self.p,
}
}

/// Returns a mutable reference to the inner value without checking if
/// it's in a mutable state.
pub(crate) fn get_mut_unchecked(&mut self) -> &mut T {
self.p
}
}

/// A wrapper around a [`Cell`] that only allows mutation based on a condition in the resolver.
Expand Down Expand Up @@ -2650,6 +2637,13 @@ mod ref_mut {
CmCell(Cell::new(value))
}

pub(crate) fn set<'ra, 'tcx>(&self, val: T, r: &Resolver<'ra, 'tcx>) {
if r.assert_speculative {
panic!()
}
self.0.set(val);
}

pub(crate) fn set_unchecked(&self, val: T) {
self.0.set(val);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use hir_def::FunctionId;
use intern::sym;
use rustc_type_ir::inherent::{Region as _, Ty as _};
use rustc_type_ir::inherent::Region as _;

use super::*;
use crate::{
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/imports/ambiguous-14.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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:18:13
--> $DIR/ambiguous-14.rs:13: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:19:13
--> $DIR/ambiguous-14.rs:14:13
|
LL | pub use f::*;
LL | pub use b::*;
| ^^^^
= help: consider adding an explicit import of `foo` to disambiguate
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
Expand All @@ -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:18:13
--> $DIR/ambiguous-14.rs:13: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:19:13
--> $DIR/ambiguous-14.rs:14:13
|
LL | pub use f::*;
LL | pub use b::*;
| ^^^^
= help: consider adding an explicit import of `foo` to disambiguate
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
Expand Down
28 changes: 0 additions & 28 deletions tests/ui/imports/ambiguous-9.rs

This file was deleted.

113 changes: 0 additions & 113 deletions tests/ui/imports/ambiguous-9.stderr

This file was deleted.

3 changes: 1 addition & 2 deletions tests/ui/imports/ambiguous-panic-globvsglob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ fn foo() {
panic!();
//~^ WARN: `panic` is ambiguous [ambiguous_panic_imports]
//~| WARN: this was previously accepted by the compiler
//~| ERROR: `panic` is ambiguous [ambiguous_glob_imports]
//~| WARN: this was previously accepted by the compiler
//~| ERROR: `panic` is ambiguous
}
30 changes: 2 additions & 28 deletions tests/ui/imports/ambiguous-panic-globvsglob.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
error: `panic` is ambiguous
error[E0659]: `panic` is ambiguous
--> $DIR/ambiguous-panic-globvsglob.rs:18:5
|
LL | panic!();
| ^^^^^ ambiguous name
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= 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: `panic` could refer to the macro imported here
--> $DIR/ambiguous-panic-globvsglob.rs:12:9
Expand All @@ -19,7 +17,6 @@ note: `panic` could also refer to the macro imported here
LL | use m2::*;
| ^^^^^
= help: consider adding an explicit import of `panic` to disambiguate
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default

warning: `panic` is ambiguous
--> $DIR/ambiguous-panic-globvsglob.rs:18:5
Expand All @@ -42,27 +39,4 @@ note: `panic` could also refer to a macro from prelude

error: aborting due to 1 previous error; 1 warning emitted

Future incompatibility report: Future breakage diagnostic:
error: `panic` is ambiguous
--> $DIR/ambiguous-panic-globvsglob.rs:18:5
|
LL | panic!();
| ^^^^^ ambiguous name
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= 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: `panic` could refer to the macro imported here
--> $DIR/ambiguous-panic-globvsglob.rs:12:9
|
LL | use m1::*;
| ^^^^^
= help: consider adding an explicit import of `panic` to disambiguate
note: `panic` could also refer to the macro imported here
--> $DIR/ambiguous-panic-globvsglob.rs:13:9
|
LL | use m2::*;
| ^^^^^
= help: consider adding an explicit import of `panic` to disambiguate
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default

For more information about this error, try `rustc --explain E0659`.
12 changes: 6 additions & 6 deletions tests/ui/imports/duplicate.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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:29:13
--> $DIR/duplicate.rs:24: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:30:13
--> $DIR/duplicate.rs:25:13
|
LL | pub use crate::f::*;
LL | pub use crate::b::*;
| ^^^^^^^^^^^
= help: consider adding an explicit import of `foo` to disambiguate
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
Expand All @@ -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:29:13
--> $DIR/duplicate.rs:24: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:30:13
--> $DIR/duplicate.rs:25:13
|
LL | pub use crate::f::*;
LL | pub use crate::b::*;
| ^^^^^^^^^^^
= help: consider adding an explicit import of `foo` to disambiguate
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/imports/import-loop-2.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mod a {
pub use crate::b::x;
pub use crate::b::x; //~ ERROR unresolved import `crate::b::x`
}

mod b {
pub use crate::a::x; //~ ERROR unresolved import `crate::a::x`
pub use crate::a::x;

fn main() { let y = x; }
}
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/imports/import-loop-2.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0432]: unresolved import `crate::a::x`
--> $DIR/import-loop-2.rs:6:13
error[E0432]: unresolved import `crate::b::x`
--> $DIR/import-loop-2.rs:2:13
|
LL | pub use crate::a::x;
| ^^^^^^^^^^^ no `x` in `a`
LL | pub use crate::b::x;
| ^^^^^^^^^^^ no `x` in `b`

error: aborting due to 1 previous error

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/imports/import4.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod a { pub use crate::b::foo; }
mod b { pub use crate::a::foo; } //~ ERROR unresolved import `crate::a::foo`
mod a { pub use crate::b::foo; } //~ ERROR unresolved import `crate::b::foo`
mod b { pub use crate::a::foo; }

fn main() { println!("loop"); }
8 changes: 4 additions & 4 deletions tests/ui/imports/import4.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0432]: unresolved import `crate::a::foo`
--> $DIR/import4.rs:2:17
error[E0432]: unresolved import `crate::b::foo`
--> $DIR/import4.rs:1:17
|
LL | mod b { pub use crate::a::foo; }
| ^^^^^^^^^^^^^ no `foo` in `a`
LL | mod a { pub use crate::b::foo; }
| ^^^^^^^^^^^^^ no `foo` in `b`

error: aborting due to 1 previous error

Expand Down
Loading
Loading