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
15 changes: 15 additions & 0 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ pub struct CStore {
unused_externs: Vec<Symbol>,

used_extern_options: FxHashSet<Symbol>,
/// Whether there was a failure in resolving crate,
/// it's used to suppress some diagnostics that would otherwise too noisey.
has_crate_resolve_with_fail: bool,
}

impl std::fmt::Debug for CStore {
Expand Down Expand Up @@ -328,6 +331,10 @@ impl CStore {
self.has_alloc_error_handler
}

pub fn had_extern_crate_load_failure(&self) -> bool {
self.has_crate_resolve_with_fail
}

pub fn report_unused_deps(&self, tcx: TyCtxt<'_>) {
let json_unused_externs = tcx.sess.opts.json_unused_externs;

Expand Down Expand Up @@ -514,6 +521,7 @@ impl CStore {
resolved_externs: UnordMap::default(),
unused_externs: Vec::new(),
used_extern_options: Default::default(),
has_crate_resolve_with_fail: false,
}
}

Expand Down Expand Up @@ -723,6 +731,13 @@ impl CStore {
}
Err(err) => {
debug!("failed to resolve crate {} {:?}", name, dep_kind);
// crate maybe injrected with `standard_library_imports::inject`, their span is dummy.
// we ignore compiler-injected prelude/sysroot loads here so they don't suppress
// unrelated diagnostics, such as `unsupported targets for std library` etc,
// these maybe helpful for users to resolve crate loading failure.
if !tcx.sess.dcx().has_errors().is_some() && !span.is_dummy() {
self.has_crate_resolve_with_fail = true;
}
let missing_core = self
.maybe_resolve_crate(
tcx,
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
}

if self.cstore().had_extern_crate_load_failure() {
self.tcx.sess.dcx().abort_if_errors();
}

if !errors.is_empty() {
self.throw_unresolved_import_error(errors, glob_error);
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//@ edition: 2024

extern crate missing_154096;
//~^ ERROR can't find crate for `missing_154096`

mod defs {
pub use missing_154096::Thing;
}

pub use defs::Thing;

mod first {
use crate::Thing;

pub fn take(_: Thing) {}
}

mod second {
use crate::Thing;

pub fn take(_: Thing) {}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0463]: can't find crate for `missing_154096`
--> $DIR/missing-extern-crate-cascade-issue-154096.rs:3:1
|
LL | extern crate missing_154096;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0463`.
20 changes: 20 additions & 0 deletions tests/ui/crate-loading/multiple-candidates-cascade-issue-118130.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//@ aux-build:crateresolve1-1.rs
//@ aux-build:crateresolve1-2.rs
//@ aux-build:crateresolve1-3.rs

//@ normalize-stderr: "multiple-candidates-cascade-issue-118130\..+/auxiliary/" -> "multiple-candidates-cascade-issue-118130/auxiliary/"
//@ normalize-stderr: "\\\?\\" -> ""
//@ normalize-stderr: "(lib)?crateresolve1-([123])\.[a-z]+" -> "libcrateresolve1-$2.somelib"

extern crate crateresolve1;
//~^ ERROR multiple candidates for `rlib` dependency `crateresolve1` found

mod defs {
pub use crateresolve1::f;
}

pub use defs::f;

fn main() {
let _ = f();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0464]: multiple candidates for `rlib` dependency `crateresolve1` found
--> $DIR/multiple-candidates-cascade-issue-118130.rs:9:1
|
LL | extern crate crateresolve1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: candidate #1: $TEST_BUILD_DIR/auxiliary/libcrateresolve1-1.somelib
= note: candidate #2: $TEST_BUILD_DIR/auxiliary/libcrateresolve1-2.somelib
= note: candidate #3: $TEST_BUILD_DIR/auxiliary/libcrateresolve1-3.somelib

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0464`.
1 change: 0 additions & 1 deletion tests/ui/rust-2018/uniform-paths/deadlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@

use bar::foo; //~ ERROR can't find crate for `bar`
use foo::bar;
//~^^ ERROR unresolved imports `bar::foo`, `foo::bar`

fn main() {}
13 changes: 2 additions & 11 deletions tests/ui/rust-2018/uniform-paths/deadlock.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ error[E0463]: can't find crate for `bar`
LL | use bar::foo;
| ^^^ can't find crate

error[E0432]: unresolved imports `bar::foo`, `foo::bar`
--> $DIR/deadlock.rs:4:5
|
LL | use bar::foo;
| ^^^^^^^^
LL | use foo::bar;
| ^^^^^^^^

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

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