Skip to content

Commit 4055afd

Browse files
committed
Update
1 parent 2180127 commit 4055afd

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

compiler/rustc_metadata/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ metadata_crate_dep_rustc_driver =
4747
metadata_crate_location_unknown_type =
4848
extern location for {$crate_name} is of an unknown type: {$path}
4949
50+
metadata_crate_not_compiler_builtins =
51+
the crate `{$crate_name}` resolved as `compiler_builtins` but is not `#![compiler_builtins]`
52+
5053
metadata_crate_not_panic_runtime =
5154
the crate `{$crate_name}` is not a panic runtime
5255

compiler/rustc_metadata/src/creader.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,18 +1040,20 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
10401040
return;
10411041
}
10421042

1043-
let Some(cnum) = self.resolve_crate(
1043+
let Ok(cnum) = self.maybe_resolve_crate(
10441044
sym::compiler_builtins,
10451045
CrateDepKind::Implicit,
10461046
CrateOrigin::Injected,
10471047
) else {
1048+
info!("`compiler_builtins` not resolved");
10481049
return;
10491050
};
10501051

1051-
if res.is_ok() {
1052-
info!("`compiler_builtins` found");
1053-
} else {
1054-
info!("`compiler_builtins` not found, skipping");
1052+
let data = self.cstore.get_crate_data(cnum);
1053+
1054+
// Sanity check the loaded crate to ensure it is indeed compiler_builtins
1055+
if !data.is_compiler_builtins() {
1056+
self.dcx().emit_err(errors::CrateNotCompilerBuiltins { crate_name: data.name() });
10551057
}
10561058
}
10571059

compiler/rustc_metadata/src/errors.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,12 @@ pub struct CrateNotPanicRuntime {
332332
pub crate_name: Symbol,
333333
}
334334

335+
#[derive(Diagnostic)]
336+
#[diag(metadata_crate_not_compiler_builtins)]
337+
pub struct CrateNotCompilerBuiltins {
338+
pub crate_name: Symbol,
339+
}
340+
335341
#[derive(Diagnostic)]
336342
#[diag(metadata_no_panic_strategy)]
337343
pub struct NoPanicStrategy {

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,10 @@ impl CrateMetadata {
19281928
self.root.profiler_runtime
19291929
}
19301930

1931+
pub(crate) fn is_compiler_builtins(&self) -> bool {
1932+
self.root.compiler_builtins
1933+
}
1934+
19311935
pub(crate) fn needs_allocator(&self) -> bool {
19321936
self.root.needs_allocator
19331937
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
error: `#[panic_handler]` function required, but not found
2+
3+
error: unwinding panics are not supported without std
4+
|
5+
= help: using nightly cargo, use -Zbuild-std with panic="abort" to avoid unwinding
6+
= note: since the core library is usually precompiled with panic="unwind", rebuilding your crate with panic="abort" may not be enough to fix the problem
7+
18
error: requires `sized` lang_item
29

3-
error: aborting due to 1 previous error
10+
error: aborting due to 3 previous errors
411

0 commit comments

Comments
 (0)