Skip to content

Commit a149bed

Browse files
committed
Ensure that crates are linked with compatible panic-in-drop settings
1 parent 007bd17 commit a149bed

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

compiler/rustc_metadata/src/dependency_format.rs

+23-9
Original file line numberDiff line numberDiff line change
@@ -400,21 +400,35 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
400400
continue;
401401
}
402402
let cnum = CrateNum::new(i + 1);
403-
let found_strategy = tcx.panic_strategy(cnum);
404-
let is_compiler_builtins = tcx.is_compiler_builtins(cnum);
405-
if is_compiler_builtins || desired_strategy == found_strategy {
403+
if tcx.is_compiler_builtins(cnum) {
406404
continue;
407405
}
408406

409-
sess.err(&format!(
410-
"the crate `{}` is compiled with the \
407+
let found_strategy = tcx.panic_strategy(cnum);
408+
if desired_strategy != found_strategy {
409+
sess.err(&format!(
410+
"the crate `{}` is compiled with the \
411411
panic strategy `{}` which is \
412412
incompatible with this crate's \
413413
strategy of `{}`",
414-
tcx.crate_name(cnum),
415-
found_strategy.desc(),
416-
desired_strategy.desc()
417-
));
414+
tcx.crate_name(cnum),
415+
found_strategy.desc(),
416+
desired_strategy.desc()
417+
));
418+
}
419+
420+
let found_drop_strategy = tcx.panic_in_drop_strategy(cnum);
421+
if tcx.sess.opts.debugging_opts.panic_in_drop != found_drop_strategy {
422+
sess.err(&format!(
423+
"the crate `{}` is compiled with the \
424+
panic-in-drop strategy `{}` which is \
425+
incompatible with this crate's \
426+
strategy of `{}`",
427+
tcx.crate_name(cnum),
428+
found_drop_strategy.desc(),
429+
tcx.sess.opts.debugging_opts.panic_in_drop.desc()
430+
));
431+
}
418432
}
419433
}
420434
}

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
160160
has_panic_handler => { cdata.root.has_panic_handler }
161161
is_profiler_runtime => { cdata.root.profiler_runtime }
162162
panic_strategy => { cdata.root.panic_strategy }
163+
panic_in_drop_strategy => { cdata.root.panic_in_drop_strategy }
163164
extern_crate => {
164165
let r = *cdata.extern_crate.lock();
165166
r.map(|c| &*tcx.arena.alloc(c))

compiler/rustc_metadata/src/rmeta/encoder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
691691
hash: tcx.crate_hash(LOCAL_CRATE),
692692
stable_crate_id: tcx.def_path_hash(LOCAL_CRATE.as_def_id()).stable_crate_id(),
693693
panic_strategy: tcx.sess.panic_strategy(),
694+
panic_in_drop_strategy: tcx.sess.opts.debugging_opts.panic_in_drop,
694695
edition: tcx.sess.edition(),
695696
has_global_allocator: tcx.has_global_allocator(LOCAL_CRATE),
696697
has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE),

compiler/rustc_metadata/src/rmeta/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ crate struct CrateRoot<'tcx> {
204204
hash: Svh,
205205
stable_crate_id: StableCrateId,
206206
panic_strategy: PanicStrategy,
207+
panic_in_drop_strategy: PanicStrategy,
207208
edition: Edition,
208209
has_global_allocator: bool,
209210
has_panic_handler: bool,

compiler/rustc_middle/src/query/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,10 @@ rustc_queries! {
11591159
fatal_cycle
11601160
desc { "query a crate's configured panic strategy" }
11611161
}
1162+
query panic_in_drop_strategy(_: CrateNum) -> PanicStrategy {
1163+
fatal_cycle
1164+
desc { "query a crate's configured panic-in-drop strategy" }
1165+
}
11621166
query is_no_builtins(_: CrateNum) -> bool {
11631167
fatal_cycle
11641168
desc { "test whether a crate has `#![no_builtins]`" }

0 commit comments

Comments
 (0)