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
337 changes: 212 additions & 125 deletions compiler/rustc_resolve/src/imports.rs

Large diffs are not rendered by default.

15 changes: 0 additions & 15 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1823,15 +1823,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 @@ -2541,12 +2532,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
}
}
}

Expand Down
8 changes: 3 additions & 5 deletions tests/ui/imports/ambiguous-9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ pub mod dsl {
mod range {
pub fn date_range() {}
}
pub use self::range::*; //~ WARNING ambiguous glob re-exports
pub use self::range::*;
use super::prelude::*;
}

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 All @@ -23,6 +23,4 @@ fn main() {
date_range();
//~^ ERROR `date_range` is ambiguous
//~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//~| ERROR `date_range` is ambiguous
//~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First import not receiving the warning is the wrong part.

}
88 changes: 17 additions & 71 deletions tests/ui/imports/ambiguous-9.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
warning: ambiguous glob re-exports
--> $DIR/ambiguous-9.rs:7:13
--> $DIR/ambiguous-9.rs:16:13
|
LL | pub use self::range::*;
| ^^^^^^^^^^^^^^ the name `date_range` in the value namespace is first re-exported here
LL | use super::prelude::*;
| ----------------- but the name `date_range` in the value namespace is also re-exported here
LL | pub use self::t::*;
| ---------- but the name `date_range` in the value namespace is also re-exported here
LL | pub use super::dsl::*;
| ^^^^^^^^^^^^^ the name `date_range` in the value namespace is first re-exported here
|
= note: `#[warn(ambiguous_glob_reexports)]` on by default

Expand All @@ -18,50 +18,20 @@ 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:7:13
--> $DIR/ambiguous-9.rs:16:13
|
LL | pub use self::range::*;
| ^^^^^^^^^^^^^^
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:8:9
|
LL | use super::prelude::*;
| ^^^^^^^^^^^^^^^^^
= help: consider adding an explicit import of `date_range` to disambiguate
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default

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

error: `date_range` is ambiguous
--> $DIR/ambiguous-9.rs:23:5
|
LL | date_range();
| ^^^^^^^^^^ 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: `date_range` could refer to the function imported here
--> $DIR/ambiguous-9.rs:19:5
|
LL | use 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
|
LL | use prelude::*;
| ^^^^^^^^^^
| ^^^^^^^^^^
= help: consider adding an explicit import of `date_range` to disambiguate
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default

error: aborting due to 2 previous errors; 2 warnings emitted
error: aborting due to 1 previous error; 1 warning emitted

Future incompatibility report: Future breakage diagnostic:
error: `date_range` is ambiguous
Expand All @@ -74,40 +44,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:7:13
|
LL | pub use self::range::*;
| ^^^^^^^^^^^^^^
= 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:8:9
|
LL | use super::prelude::*;
| ^^^^^^^^^^^^^^^^^
= help: consider adding an explicit import of `date_range` to disambiguate
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default

Future breakage diagnostic:
error: `date_range` is ambiguous
--> $DIR/ambiguous-9.rs:23:5
|
LL | date_range();
| ^^^^^^^^^^ 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: `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: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default

2 changes: 1 addition & 1 deletion tests/ui/imports/glob-conflict-cross-crate-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn main() {
glob_conflict::f(); //~ ERROR cannot find function `f` in crate `glob_conflict`
//^ FIXME: `glob_conflict::f` should raise an
// ambiguity error instead of a not found error.
glob_conflict::glob::f(); //~ ERROR cannot find function `f` in module `glob_conflict::glob`
glob_conflict::glob::f();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also wrong, I believe. Should give an error or a warning.

//^ FIXME: `glob_conflict::glob::f` should raise an
// ambiguity error instead of a not found error.
}
16 changes: 10 additions & 6 deletions tests/ui/imports/glob-conflict-cross-crate-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ error[E0425]: cannot find function `f` in crate `glob_conflict`
|
LL | glob_conflict::f();
| ^ not found in `glob_conflict`

error[E0425]: cannot find function `f` in module `glob_conflict::glob`
--> $DIR/glob-conflict-cross-crate-1.rs:9:26
|
LL | glob_conflict::glob::f();
| ^ not found in `glob_conflict::glob`
help: consider importing this function
|
LL + use glob_conflict::glob::f;
|
help: if you import `f`, refer to it directly
|
LL - glob_conflict::f();
LL + f();
|

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0425`.
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
24 changes: 12 additions & 12 deletions tests/ui/privacy/privacy1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ LL | mod baz {
| ^^^^^^^
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0603]: module `baz` is private
--> $DIR/privacy1.rs:147:18
|
LL | use bar::baz;
| ^^^ private module
|
note: the module `baz` is defined here
--> $DIR/privacy1.rs:56:5
|
LL | mod baz {
| ^^^^^^^

error[E0603]: module `i` is private
--> $DIR/privacy1.rs:171:20
|
Expand All @@ -47,6 +35,18 @@ note: the module `i` is defined here
LL | mod i {
| ^^^^^

error[E0603]: module `baz` is private
--> $DIR/privacy1.rs:147:18
|
LL | use bar::baz;
| ^^^ private module
|
note: the module `baz` is defined here
--> $DIR/privacy1.rs:56:5
|
LL | mod baz {
| ^^^^^^^

error[E0603]: module `baz` is private
--> $DIR/privacy1.rs:110:21
|
Expand Down
32 changes: 16 additions & 16 deletions tests/ui/shadowed/shadowed-use-visibility.stderr
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
error[E0603]: module import `bar` is private
--> $DIR/shadowed-use-visibility.rs:9:21
error[E0603]: module import `f` is private
--> $DIR/shadowed-use-visibility.rs:15:10
|
LL | use crate::foo::bar::f as g;
| ^^^ private module import
LL | use bar::f::f;
| ^ private module import
|
note: the module import `bar` is defined here...
--> $DIR/shadowed-use-visibility.rs:4:9
note: the module import `f` is defined here...
--> $DIR/shadowed-use-visibility.rs:11:9
|
LL | use crate::foo as bar;
| ^^^^^^^^^^^^^^^^^
LL | use crate::foo as f;
| ^^^^^^^^^^^^^^^
note: ...and refers to the module `foo` which is defined here
--> $DIR/shadowed-use-visibility.rs:1:1
|
LL | mod foo {
| ^^^^^^^

error[E0603]: module import `f` is private
--> $DIR/shadowed-use-visibility.rs:15:10
error[E0603]: module import `bar` is private
--> $DIR/shadowed-use-visibility.rs:9:21
|
LL | use bar::f::f;
| ^ private module import
LL | use crate::foo::bar::f as g;
| ^^^ private module import
|
note: the module import `f` is defined here...
--> $DIR/shadowed-use-visibility.rs:11:9
note: the module import `bar` is defined here...
--> $DIR/shadowed-use-visibility.rs:4:9
|
LL | use crate::foo as f;
| ^^^^^^^^^^^^^^^
LL | use crate::foo as bar;
| ^^^^^^^^^^^^^^^^^
note: ...and refers to the module `foo` which is defined here
--> $DIR/shadowed-use-visibility.rs:1:1
|
Expand Down
Loading