Skip to content

Commit 77fd0cc

Browse files
committed
Handle panic runtime specially
1 parent 6ef2033 commit 77fd0cc

File tree

6 files changed

+20
-17
lines changed

6 files changed

+20
-17
lines changed

compiler/rustc_metadata/src/dependency_format.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,19 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
366366
prev_name, cur_name
367367
));
368368
}
369-
panic_runtime = Some((cnum, tcx.panic_strategy(cnum).unwrap()));
369+
panic_runtime = Some((
370+
cnum,
371+
tcx.panic_strategy(cnum).unwrap_or_else(|| {
372+
bug!("cannot determine panic strategy of a panic runtime");
373+
}),
374+
));
370375
}
371376
}
372377

373378
// If we found a panic runtime, then we know by this point that it's the
374379
// only one, but we perform validation here that all the panic strategy
375380
// compilation modes for the whole DAG are valid.
376-
if let Some((cnum, found_strategy)) = panic_runtime {
381+
if let Some((runtime_cnum, found_strategy)) = panic_runtime {
377382
let desired_strategy = sess.panic_strategy();
378383

379384
// First up, validate that our selected panic runtime is indeed exactly
@@ -383,7 +388,7 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
383388
"the linked panic runtime `{}` is \
384389
not compiled with this crate's \
385390
panic strategy `{}`",
386-
tcx.crate_name(cnum),
391+
tcx.crate_name(runtime_cnum),
387392
desired_strategy.desc()
388393
));
389394
}
@@ -397,7 +402,7 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
397402
continue;
398403
}
399404
let cnum = CrateNum::new(i + 1);
400-
if tcx.is_compiler_builtins(cnum) {
405+
if cnum == runtime_cnum || tcx.is_compiler_builtins(cnum) {
401406
continue;
402407
}
403408

compiler/rustc_mir_transform/src/ffi_unwind_calls.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_hir::def::DefKind;
2-
use rustc_hir::def_id::LocalDefId;
2+
use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
33
use rustc_middle::mir::*;
44
use rustc_middle::ty::layout;
55
use rustc_middle::ty::query::Providers;
@@ -129,6 +129,10 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool {
129129
}
130130

131131
fn required_panic_strategy(tcx: TyCtxt<'_>, (): ()) -> Option<PanicStrategy> {
132+
if tcx.is_panic_runtime(LOCAL_CRATE) {
133+
return Some(tcx.sess.panic_strategy());
134+
}
135+
132136
if tcx.sess.panic_strategy() == PanicStrategy::Abort {
133137
return Some(PanicStrategy::Abort);
134138
}

src/test/ui/panic-runtime/transitive-link-a-bunch.stderr

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error: cannot link together two panic runtimes: panic_runtime_unwind and panic_r
22

33
error: the linked panic runtime `panic_runtime_abort` is not compiled with this crate's panic strategy `unwind`
44

5-
error: the crate `wants_panic_runtime_abort` is compiled with the panic strategy `abort` which is incompatible with this crate's strategy of `unwind`
5+
error: the crate `wants_panic_runtime_abort` requires panic strategy `abort` which is incompatible with this crate's strategy of `unwind`
66

7-
error: the crate `panic_runtime_abort` is compiled with the panic strategy `abort` which is incompatible with this crate's strategy of `unwind`
8-
9-
error: aborting due to 4 previous errors
7+
error: aborting due to 3 previous errors
108

src/test/ui/panic-runtime/want-unwind-got-abort.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// build-fail
22
// needs-unwind
3-
// error-pattern:is incompatible with this crate's strategy of `unwind`
3+
// error-pattern:is not compiled with this crate's panic strategy `unwind`
44
// aux-build:panic-runtime-abort.rs
55
// aux-build:panic-runtime-lang-items.rs
66
// ignore-wasm32-bare compiled with panic=abort by default
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
error: the linked panic runtime `panic_runtime_abort` is not compiled with this crate's panic strategy `unwind`
22

3-
error: the crate `panic_runtime_abort` is compiled with the panic strategy `abort` which is incompatible with this crate's strategy of `unwind`
4-
5-
error: aborting due to 2 previous errors
3+
error: aborting due to previous error
64

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
error: the linked panic runtime `panic_runtime_abort` is not compiled with this crate's panic strategy `unwind`
22

3-
error: the crate `wants_panic_runtime_abort` is compiled with the panic strategy `abort` which is incompatible with this crate's strategy of `unwind`
3+
error: the crate `wants_panic_runtime_abort` requires panic strategy `abort` which is incompatible with this crate's strategy of `unwind`
44

5-
error: the crate `panic_runtime_abort` is compiled with the panic strategy `abort` which is incompatible with this crate's strategy of `unwind`
6-
7-
error: aborting due to 3 previous errors
5+
error: aborting due to 2 previous errors
86

0 commit comments

Comments
 (0)