Skip to content

Commit 9b6bdcd

Browse files
committed
Suggest x build library for a custom toolchain that fails to load core
1 parent 0ab38e9 commit 9b6bdcd

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

compiler/rustc_metadata/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ metadata_conflicting_alloc_error_handler =
2525
metadata_conflicting_global_alloc =
2626
the `#[global_allocator]` in {$other_crate_name} conflicts with global allocator in: {$crate_name}
2727
28+
metadata_consider_adding_std =
29+
consider adding the standard library to the sysroot with `x build library --target {$locator_triple}`
30+
2831
metadata_consider_building_std =
2932
consider building the standard library from source with `cargo build -Zbuild-std`
3033

compiler/rustc_metadata/src/errors.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ pub struct CannotFindCrate {
623623
pub is_nightly_build: bool,
624624
pub profiler_runtime: Symbol,
625625
pub locator_triple: TargetTriple,
626+
pub is_ui_testing: bool,
626627
}
627628

628629
impl IntoDiagnostic<'_> for CannotFindCrate {
@@ -646,12 +647,19 @@ impl IntoDiagnostic<'_> for CannotFindCrate {
646647
} else {
647648
diag.note(fluent::metadata_target_no_std_support);
648649
}
649-
// NOTE: this suggests using rustup, even though the user may not have it installed.
650-
// That's because they could choose to install it; or this may give them a hint which
651-
// target they need to install from their distro.
650+
652651
if self.missing_core {
653-
diag.help(fluent::metadata_consider_downloading_target);
652+
if env!("CFG_RELEASE_CHANNEL") == "dev" && !self.is_ui_testing {
653+
// Note: Emits the nicer suggestion only for the dev channel.
654+
diag.help(fluent::metadata_consider_adding_std);
655+
} else {
656+
// NOTE: this suggests using rustup, even though the user may not have it installed.
657+
// That's because they could choose to install it; or this may give them a hint which
658+
// target they need to install from their distro.
659+
diag.help(fluent::metadata_consider_downloading_target);
660+
}
654661
}
662+
655663
// Suggest using #![no_std]. #[no_core] is unstable and not really supported anyway.
656664
// NOTE: this is a dummy span if `extern crate std` was injected by the compiler.
657665
// If it's not a dummy, that means someone added `extern crate std` explicitly and

compiler/rustc_metadata/src/locator.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@ impl CrateError {
11251125
is_nightly_build: sess.is_nightly_build(),
11261126
profiler_runtime: Symbol::intern(&sess.opts.unstable_opts.profiler_runtime),
11271127
locator_triple: locator.triple,
1128+
is_ui_testing: sess.opts.unstable_opts.ui_testing,
11281129
});
11291130
}
11301131
}
@@ -1141,6 +1142,7 @@ impl CrateError {
11411142
is_nightly_build: sess.is_nightly_build(),
11421143
profiler_runtime: Symbol::intern(&sess.opts.unstable_opts.profiler_runtime),
11431144
locator_triple: sess.opts.target_triple.clone(),
1145+
is_ui_testing: sess.opts.unstable_opts.ui_testing,
11441146
});
11451147
}
11461148
}

0 commit comments

Comments
 (0)