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 @@ -1219,6 +1219,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 @@ -1616,6 +1617,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

glob_map: Default::default(),
maybe_unused_trait_imports: Default::default(),
macro_vis_hack_map: Default::default(),

arenas,
dummy_decl: arenas.new_pub_def_decl(Res::Err, DUMMY_SP, LocalExpnId::ROOT),
Expand Down Expand Up @@ -1831,15 +1833,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 @@ -2581,12 +2574,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 @@ -2624,6 +2611,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: `#[warn(ambiguous_glob_imports)]` (part of `#[warn(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: `#[warn(ambiguous_glob_imports)]` (part of `#[warn(future_incompatible)]`) on by default
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/imports/ambiguous-9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub mod prelude {
mod t {
pub fn date_range() {}
}
pub use self::t::*; //~ WARNING ambiguous glob re-exports
pub use super::dsl::*;
pub use self::t::*;
pub use super::dsl::*; //~ WARNING ambiguous glob re-exports
}

use dsl::*;
Expand Down
30 changes: 15 additions & 15 deletions tests/ui/imports/ambiguous-9.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ LL | use super::prelude::*;
= note: `#[warn(ambiguous_glob_imports)]` (part of `#[warn(future_incompatible)]`) on by default

warning: ambiguous glob re-exports
--> $DIR/ambiguous-9.rs:15:13
--> $DIR/ambiguous-9.rs:16:13
|
LL | pub use self::t::*;
| ^^^^^^^^^^ the name `date_range` in the value namespace is first re-exported here
| ---------- but the name `date_range` in the value namespace is also re-exported here
LL | pub use super::dsl::*;
| ------------- but the name `date_range` in the value namespace is also re-exported here
| ^^^^^^^^^^^^^ the name `date_range` in the value namespace is first re-exported here

warning: `date_range` is ambiguous
--> $DIR/ambiguous-9.rs:23:5
Expand All @@ -49,16 +49,16 @@ LL | date_range();
= 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: `date_range` could refer to the function imported here
--> $DIR/ambiguous-9.rs:19:5
--> $DIR/ambiguous-9.rs:16:13
|
LL | use dsl::*;
| ^^^^^^
LL | pub use super::dsl::*;
| ^^^^^^^^^^^^^
= help: consider adding an explicit import of `date_range` to disambiguate
note: `date_range` could also refer to the function imported here
--> $DIR/ambiguous-9.rs:20:5
--> $DIR/ambiguous-9.rs:15:13
|
LL | use prelude::*;
| ^^^^^^^^^^
LL | pub use self::t::*;
| ^^^^^^^^^^
= help: consider adding an explicit import of `date_range` to disambiguate

warning: 4 warnings emitted
Expand Down Expand Up @@ -98,16 +98,16 @@ LL | date_range();
= 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: `date_range` could refer to the function imported here
--> $DIR/ambiguous-9.rs:19:5
--> $DIR/ambiguous-9.rs:16:13
|
LL | use dsl::*;
| ^^^^^^
LL | pub use super::dsl::*;
| ^^^^^^^^^^^^^
= help: consider adding an explicit import of `date_range` to disambiguate
note: `date_range` could also refer to the function imported here
--> $DIR/ambiguous-9.rs:20:5
--> $DIR/ambiguous-9.rs:15:13
|
LL | use prelude::*;
| ^^^^^^^^^^
LL | pub use self::t::*;
| ^^^^^^^^^^
= help: consider adding an explicit import of `date_range` to disambiguate
= note: `#[warn(ambiguous_glob_imports)]` (part of `#[warn(future_incompatible)]`) on by default

4 changes: 1 addition & 3 deletions tests/ui/imports/ambiguous-panic-globvsglob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
mod m1 {
pub use core::prelude::v1::*;
}
//@ check-pass
mod m2 {
pub use std::prelude::v1::*;
}
Expand All @@ -18,6 +17,5 @@ fn foo() {
panic!();
//~^ WARN: `panic` is ambiguous [ambiguous_panic_imports]
//~| WARN: this was previously accepted by the compiler
//~| WARN: `panic` is ambiguous [ambiguous_glob_imports]
//~| WARN: this was previously accepted by the compiler
//~| ERROR: `panic` is ambiguous
}
42 changes: 8 additions & 34 deletions tests/ui/imports/ambiguous-panic-globvsglob.stderr
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
warning: `panic` is ambiguous
--> $DIR/ambiguous-panic-globvsglob.rs:18:5
error[E0659]: `panic` is ambiguous
--> $DIR/ambiguous-panic-globvsglob.rs:17: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
--> $DIR/ambiguous-panic-globvsglob.rs:11: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
--> $DIR/ambiguous-panic-globvsglob.rs:12:9
|
LL | use m2::*;
| ^^^^^
= help: consider adding an explicit import of `panic` to disambiguate
= note: `#[warn(ambiguous_glob_imports)]` (part of `#[warn(future_incompatible)]`) on by default

warning: `panic` is ambiguous
--> $DIR/ambiguous-panic-globvsglob.rs:18:5
--> $DIR/ambiguous-panic-globvsglob.rs:17:5
|
LL | panic!();
| ^^^^^ ambiguous name
Expand All @@ -31,7 +28,7 @@ LL | panic!();
= note: for more information, see issue #147319 <https://github.com/rust-lang/rust/issues/147319>
= note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
note: `panic` could refer to the macro imported here
--> $DIR/ambiguous-panic-globvsglob.rs:12:9
--> $DIR/ambiguous-panic-globvsglob.rs:11:9
|
LL | use m1::*;
| ^^^^^
Expand All @@ -40,29 +37,6 @@ note: `panic` could also refer to a macro from prelude
--> $SRC_DIR/std/src/prelude/mod.rs:LL:COL
= note: `#[warn(ambiguous_panic_imports)]` (part of `#[warn(future_incompatible)]`) on by default

warning: 2 warnings emitted

Future incompatibility report: Future breakage diagnostic:
warning: `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: `#[warn(ambiguous_glob_imports)]` (part of `#[warn(future_incompatible)]`) on by default
error: aborting due to 1 previous error; 1 warning emitted

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: `#[warn(ambiguous_glob_imports)]` (part of `#[warn(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: `#[warn(ambiguous_glob_imports)]` (part of `#[warn(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
20 changes: 0 additions & 20 deletions tests/ui/imports/same-res-ambigious.fail.stderr

This file was deleted.

4 changes: 2 additions & 2 deletions tests/ui/imports/same-res-ambigious.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//@ check-pass
//@ edition: 2018
//@ revisions: fail pass
//@[pass] check-pass
//@[pass] aux-crate: ambigious_extern=same-res-ambigious-extern.rs
//@[fail] aux-crate: ambigious_extern=same-res-ambigious-extern-fail.rs
// see https://github.com/rust-lang/rust/pull/147196

#[derive(ambigious_extern::Embed)] //[fail]~ ERROR: derive macro `Embed` is private
#[derive(ambigious_extern::Embed)]
struct Foo{}

fn main(){}
Loading
Loading