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
364 changes: 233 additions & 131 deletions compiler/rustc_resolve/src/imports.rs

Large diffs are not rendered by default.

35 changes: 21 additions & 14 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2654,16 +2654,10 @@ mod ref_mut {
#[track_caller]
pub(crate) fn get_mut(&mut self) -> &mut T {
match self.mutable {
false => panic!("Can't mutably borrow speculative resolver"),
false => panic!("can't mutably borrow speculative resolver"),
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 All @@ -2687,12 +2681,12 @@ mod ref_mut {
self.0.get()
}

pub(crate) fn update_unchecked(&self, f: impl FnOnce(T) -> T)
pub(crate) fn update<'ra, 'tcx>(&self, r: &Resolver<'ra, 'tcx>, f: impl FnOnce(T) -> T)
where
T: Copy,
{
let old = self.get();
self.set_unchecked(f(old));
self.set(f(old), r);
}
}

Expand All @@ -2701,7 +2695,10 @@ mod ref_mut {
CmCell(Cell::new(value))
}

pub(crate) fn set_unchecked(&self, val: T) {
pub(crate) fn set<'ra, 'tcx>(&self, val: T, r: &Resolver<'ra, 'tcx>) {
if r.assert_speculative {
panic!("not allowed to mutate a `CmCell` during speculative resolution")
}
self.0.set(val);
}

Expand All @@ -2727,16 +2724,26 @@ mod ref_mut {
#[track_caller]
pub(crate) fn borrow_mut<'ra, 'tcx>(&self, r: &Resolver<'ra, 'tcx>) -> RefMut<'_, T> {
if r.assert_speculative {
panic!("Not allowed to mutably borrow a CmRefCell during speculative resolution");
panic!("not allowed to mutably borrow a `CmRefCell` during speculative resolution");
}
self.borrow_mut_unchecked()
self.0.borrow_mut()
}

#[track_caller]
pub(crate) fn try_borrow_mut_unchecked(&self) -> Result<RefMut<'_, T>, BorrowMutError> {
self.0.try_borrow_mut()
}

#[track_caller]
pub(crate) fn try_borrow_mut<'ra, 'tcx>(
&self,
r: &Resolver<'ra, 'tcx>,
) -> Result<RefMut<'_, T>, BorrowMutError> {
if r.assert_speculative {
panic!("not allowed to mutably borrow a `CmRefCell` during speculative resolution");
}
self.0.try_borrow_mut()
}

#[track_caller]
pub(crate) fn borrow(&self) -> Ref<'_, T> {
self.0.borrow()
Expand All @@ -2746,7 +2753,7 @@ mod ref_mut {
impl<T: Default> CmRefCell<T> {
pub(crate) fn take<'ra, 'tcx>(&self, r: &Resolver<'ra, 'tcx>) -> T {
if r.assert_speculative {
panic!("Not allowed to mutate a CmRefCell during speculative resolution");
panic!("not allowed to mutate a CmRefCell during speculative resolution");
}
self.0.take()
}
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 @@ -6,15 +6,15 @@ LL | g::foo();
|
= 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
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
Expand All @@ -32,15 +32,15 @@ LL | g::foo();
|
= 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
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
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: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(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

error: `date_range` is ambiguous
--> $DIR/ambiguous-9.rs:23:5
Expand All @@ -47,16 +47,16 @@ LL | date_range();
|
= 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: 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>
Expand Down Expand Up @@ -96,16 +96,16 @@ LL | date_range();
|
= 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: 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>
Expand Down
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,4 +1,4 @@
error: `panic` is ambiguous
error[E0659]: `panic` is ambiguous
--> $DIR/ambiguous-panic-globvsglob.rs:18:5
|
LL | panic!();
Expand All @@ -17,9 +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
= 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: `#[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
|
= 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
= 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: `#[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 @@ -76,15 +76,15 @@ LL | g::foo();
|
= 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
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
Expand All @@ -104,15 +104,15 @@ LL | g::foo();
|
= 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
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
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