Skip to content
Merged
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
8 changes: 6 additions & 2 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
message,
} => {
if no_ambiguity {
assert!(import.imported_module.get().is_none());
if !self.issue_145575_hack_applied {
assert!(import.imported_module.get().is_none());
}
self.report_error(
span,
ResolutionError::FailedToResolve {
Expand All @@ -1072,7 +1074,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
..
} => {
if no_ambiguity {
assert!(import.imported_module.get().is_none());
if !self.issue_145575_hack_applied {
assert!(import.imported_module.get().is_none());
}
let module = if let Some(ModuleOrUniformRoot::Module(m)) = module {
m.opt_def_id()
} else {
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/resolve/ice-on-shadowing-std-with-attr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ edition: 2024
// This test ensures that `extern crate` with attribute shadowing std does not cause ICE.
// Issue link: https://github.com/rust-lang/rust/issues/152895

#![crate_type = "lib"]

#[foobar] //~ ERROR cannot find attribute `foobar` in this scope
extern crate core as std; //~ ERROR macro-expanded `extern crate` items cannot shadow names passed with `--extern`
mod inner {
use std::collections::hash_map::HashMap; //~ ERROR cannot find `collections` in `std`
use std::vec::IntoIter; //~ ERROR unresolved import `std::vec`

use crate::*;
}
28 changes: 28 additions & 0 deletions tests/ui/resolve/ice-on-shadowing-std-with-attr.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
error: macro-expanded `extern crate` items cannot shadow names passed with `--extern`
--> $DIR/ice-on-shadowing-std-with-attr.rs:8:1
|
LL | extern crate core as std;
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0433]: cannot find `collections` in `std`
--> $DIR/ice-on-shadowing-std-with-attr.rs:10:14
|
LL | use std::collections::hash_map::HashMap;
| ^^^^^^^^^^^ could not find `collections` in `std`

error[E0432]: unresolved import `std::vec`
--> $DIR/ice-on-shadowing-std-with-attr.rs:11:14
|
LL | use std::vec::IntoIter;
| ^^^ could not find `vec` in `std`

error: cannot find attribute `foobar` in this scope
--> $DIR/ice-on-shadowing-std-with-attr.rs:7:3
|
LL | #[foobar]
| ^^^^^^

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0432, E0433.
For more information about an error, try `rustc --explain E0432`.
19 changes: 19 additions & 0 deletions tests/ui/resolve/ice-on-shadowing-std-with-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//@ edition: 2024
// This test ensures that a macro-expanded `extern crate` shadowing std does not cause ICE.
// Issue link: https://github.com/rust-lang/rust/issues/152895

#![crate_type = "lib"]

mod inner {
use std::collections::hash_map::HashMap; //~ ERROR cannot find `collections` in `std`
use std::vec::IntoIter; //~ ERROR unresolved import `std::vec`

use crate::*;
}

macro_rules! define_other_core {
() => {
extern crate core as std; //~ ERROR macro-expanded `extern crate` items cannot shadow names passed with `--extern`
};
}
define_other_core! {}
27 changes: 27 additions & 0 deletions tests/ui/resolve/ice-on-shadowing-std-with-macro.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
error: macro-expanded `extern crate` items cannot shadow names passed with `--extern`
--> $DIR/ice-on-shadowing-std-with-macro.rs:16:9
|
LL | extern crate core as std;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | define_other_core! {}
| --------------------- in this macro invocation
|
= note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: cannot find `collections` in `std`
--> $DIR/ice-on-shadowing-std-with-macro.rs:8:14
|
LL | use std::collections::hash_map::HashMap;
| ^^^^^^^^^^^ could not find `collections` in `std`

error[E0432]: unresolved import `std::vec`
--> $DIR/ice-on-shadowing-std-with-macro.rs:9:14
|
LL | use std::vec::IntoIter;
| ^^^ could not find `vec` in `std`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0432, E0433.
For more information about an error, try `rustc --explain E0432`.
Loading