Skip to content

Commit c0c22d1

Browse files
authored
Rollup merge of #154713 - chenyukang:yukang-fix-154096-missing-crate-noise, r=kivooeo
Stop compiling when we get resolving crate failure Fixes #154096 closes #118130
2 parents 4cb5357 + cd95593 commit c0c22d1

File tree

8 files changed

+87
-12
lines changed

8 files changed

+87
-12
lines changed

compiler/rustc_metadata/src/creader.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ pub struct CStore {
7777
unused_externs: Vec<Symbol>,
7878

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

8285
impl std::fmt::Debug for CStore {
@@ -328,6 +331,10 @@ impl CStore {
328331
self.has_alloc_error_handler
329332
}
330333

334+
pub fn had_extern_crate_load_failure(&self) -> bool {
335+
self.has_crate_resolve_with_fail
336+
}
337+
331338
pub fn report_unused_deps(&self, tcx: TyCtxt<'_>) {
332339
let json_unused_externs = tcx.sess.opts.json_unused_externs;
333340

@@ -514,6 +521,7 @@ impl CStore {
514521
resolved_externs: UnordMap::default(),
515522
unused_externs: Vec::new(),
516523
used_extern_options: Default::default(),
524+
has_crate_resolve_with_fail: false,
517525
}
518526
}
519527

@@ -723,6 +731,13 @@ impl CStore {
723731
}
724732
Err(err) => {
725733
debug!("failed to resolve crate {} {:?}", name, dep_kind);
734+
// crate maybe injrected with `standard_library_imports::inject`, their span is dummy.
735+
// we ignore compiler-injected prelude/sysroot loads here so they don't suppress
736+
// unrelated diagnostics, such as `unsupported targets for std library` etc,
737+
// these maybe helpful for users to resolve crate loading failure.
738+
if !tcx.sess.dcx().has_errors().is_some() && !span.is_dummy() {
739+
self.has_crate_resolve_with_fail = true;
740+
}
726741
let missing_core = self
727742
.maybe_resolve_crate(
728743
tcx,

compiler/rustc_resolve/src/imports.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
674674
}
675675
}
676676

677+
if self.cstore().had_extern_crate_load_failure() {
678+
self.tcx.sess.dcx().abort_if_errors();
679+
}
680+
677681
if !errors.is_empty() {
678682
self.throw_unresolved_import_error(errors, glob_error);
679683
return;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//@ edition: 2024
2+
3+
extern crate missing_154096;
4+
//~^ ERROR can't find crate for `missing_154096`
5+
6+
mod defs {
7+
pub use missing_154096::Thing;
8+
}
9+
10+
pub use defs::Thing;
11+
12+
mod first {
13+
use crate::Thing;
14+
15+
pub fn take(_: Thing) {}
16+
}
17+
18+
mod second {
19+
use crate::Thing;
20+
21+
pub fn take(_: Thing) {}
22+
}
23+
24+
fn main() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0463]: can't find crate for `missing_154096`
2+
--> $DIR/missing-extern-crate-cascade-issue-154096.rs:3:1
3+
|
4+
LL | extern crate missing_154096;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0463`.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ aux-build:crateresolve1-1.rs
2+
//@ aux-build:crateresolve1-2.rs
3+
//@ aux-build:crateresolve1-3.rs
4+
5+
//@ normalize-stderr: "multiple-candidates-cascade-issue-118130\..+/auxiliary/" -> "multiple-candidates-cascade-issue-118130/auxiliary/"
6+
//@ normalize-stderr: "\\\?\\" -> ""
7+
//@ normalize-stderr: "(lib)?crateresolve1-([123])\.[a-z]+" -> "libcrateresolve1-$2.somelib"
8+
9+
extern crate crateresolve1;
10+
//~^ ERROR multiple candidates for `rlib` dependency `crateresolve1` found
11+
12+
mod defs {
13+
pub use crateresolve1::f;
14+
}
15+
16+
pub use defs::f;
17+
18+
fn main() {
19+
let _ = f();
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0464]: multiple candidates for `rlib` dependency `crateresolve1` found
2+
--> $DIR/multiple-candidates-cascade-issue-118130.rs:9:1
3+
|
4+
LL | extern crate crateresolve1;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: candidate #1: $TEST_BUILD_DIR/auxiliary/libcrateresolve1-1.somelib
8+
= note: candidate #2: $TEST_BUILD_DIR/auxiliary/libcrateresolve1-2.somelib
9+
= note: candidate #3: $TEST_BUILD_DIR/auxiliary/libcrateresolve1-3.somelib
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0464`.

tests/ui/rust-2018/uniform-paths/deadlock.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33

44
use bar::foo; //~ ERROR can't find crate for `bar`
55
use foo::bar;
6-
//~^^ ERROR unresolved imports `bar::foo`, `foo::bar`
76

87
fn main() {}

tests/ui/rust-2018/uniform-paths/deadlock.stderr

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ error[E0463]: can't find crate for `bar`
44
LL | use bar::foo;
55
| ^^^ can't find crate
66

7-
error[E0432]: unresolved imports `bar::foo`, `foo::bar`
8-
--> $DIR/deadlock.rs:4:5
9-
|
10-
LL | use bar::foo;
11-
| ^^^^^^^^
12-
LL | use foo::bar;
13-
| ^^^^^^^^
14-
15-
error: aborting due to 2 previous errors
7+
error: aborting due to 1 previous error
168

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

0 commit comments

Comments
 (0)