Skip to content

Commit

Permalink
Rollup merge of rust-lang#122114 - saethlin:cant-find-crate-spam, r=W…
Browse files Browse the repository at this point in the history
…affleLapkin

Make not finding core a fatal error

Similar to rust-lang#120472, this prevents terminal spam. In particular, it makes the good diagnostic visible when you try to use a target that's not installed.
  • Loading branch information
workingjubilee committed Mar 7, 2024
2 parents c6dfdc7 + 52bc7ce commit a88c35d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
22 changes: 18 additions & 4 deletions compiler/rustc_metadata/src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ impl CrateError {
crate_rejections,
});
} else {
dcx.emit_err(errors::CannotFindCrate {
let error = errors::CannotFindCrate {
span,
crate_name,
add_info,
Expand All @@ -1091,11 +1091,18 @@ impl CrateError {
profiler_runtime: Symbol::intern(&sess.opts.unstable_opts.profiler_runtime),
locator_triple: locator.triple,
is_ui_testing: sess.opts.unstable_opts.ui_testing,
});
};
// The diagnostic for missing core is very good, but it is followed by a lot of
// other diagnostics that do not add information.
if missing_core {
dcx.emit_fatal(error);
} else {
dcx.emit_err(error);
}
}
}
CrateError::NotFound(crate_name) => {
dcx.emit_err(errors::CannotFindCrate {
let error = errors::CannotFindCrate {
span,
crate_name,
add_info: String::new(),
Expand All @@ -1105,7 +1112,14 @@ impl CrateError {
profiler_runtime: Symbol::intern(&sess.opts.unstable_opts.profiler_runtime),
locator_triple: sess.opts.target_triple.clone(),
is_ui_testing: sess.opts.unstable_opts.ui_testing,
});
};
// The diagnostic for missing core is very good, but it is followed by a lot of
// other diagnostics that do not add information.
if missing_core {
dcx.emit_fatal(error);
} else {
dcx.emit_err(error);
}
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions tests/ui/crate-loading/missing-std.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ LL | extern crate core;
= help: consider downloading the target with `rustup target add x86_64-unknown-uefi`
= help: consider building the standard library from source with `cargo build -Zbuild-std`

error: requires `sized` lang_item

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

For more information about this error, try `rustc --explain E0463`.
4 changes: 1 addition & 3 deletions tests/ui/issues/issue-37131.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ error[E0463]: can't find crate for `std`
= help: consider downloading the target with `rustup target add thumbv6m-none-eabi`
= help: consider building the standard library from source with `cargo build -Zbuild-std`

error: requires `sized` lang_item

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

For more information about this error, try `rustc --explain E0463`.
2 changes: 0 additions & 2 deletions tests/ui/issues/issue-49851/compiler-builtins-error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//~ ERROR can't find crate for `core`
//~^ ERROR can't find crate for `compiler_builtins`

//@ compile-flags: --target thumbv7em-none-eabihf
//@ needs-llvm-components: arm
Expand All @@ -8,6 +7,5 @@
#![no_std]

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

fn main() {}
12 changes: 1 addition & 11 deletions tests/ui/issues/issue-49851/compiler-builtins-error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ error[E0463]: can't find crate for `core`
= help: consider downloading the target with `rustup target add thumbv7em-none-eabihf`
= help: consider building the standard library from source with `cargo build -Zbuild-std`

error[E0463]: can't find crate for `compiler_builtins`

error[E0463]: can't find crate for `cortex_m`
--> $DIR/compiler-builtins-error.rs:10:1
|
LL | extern crate cortex_m;
| ^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: requires `sized` lang_item

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

For more information about this error, try `rustc --explain E0463`.

0 comments on commit a88c35d

Please sign in to comment.