Skip to content

Commit aa70e5f

Browse files
committed
Auto merge of rust-lang#113292 - MU001999:fix/issue-113222, r=Nilstrieb
Suggest `x build library` for a custom toolchain that fails to load `core` Fixes rust-lang#113222 The nicer suggestion for dev-channel won't be emitted if `-Z ui-testing` enabled. IMO, this is acceptable for now.
2 parents 736ef39 + 9b6bdcd commit aa70e5f

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
@@ -1130,6 +1130,7 @@ impl CrateError {
11301130
is_nightly_build: sess.is_nightly_build(),
11311131
profiler_runtime: Symbol::intern(&sess.opts.unstable_opts.profiler_runtime),
11321132
locator_triple: locator.triple,
1133+
is_ui_testing: sess.opts.unstable_opts.ui_testing,
11331134
});
11341135
}
11351136
}
@@ -1146,6 +1147,7 @@ impl CrateError {
11461147
is_nightly_build: sess.is_nightly_build(),
11471148
profiler_runtime: Symbol::intern(&sess.opts.unstable_opts.profiler_runtime),
11481149
locator_triple: sess.opts.target_triple.clone(),
1150+
is_ui_testing: sess.opts.unstable_opts.ui_testing,
11491151
});
11501152
}
11511153
}

0 commit comments

Comments
 (0)