Skip to content

Commit 692ae3d

Browse files
Move has_panic_handler to query
1 parent 87cbf0a commit 692ae3d

File tree

4 files changed

+6
-11
lines changed

4 files changed

+6
-11
lines changed

src/librustc/session/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ pub struct Session {
156156
/// Metadata about the allocators for the current crate being compiled.
157157
pub has_global_allocator: Once<bool>,
158158

159-
/// Metadata about the panic handlers for the current crate being compiled.
160-
pub has_panic_handler: Once<bool>,
161-
162159
/// Cap lint level specified by a driver specifically.
163160
pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
164161

@@ -1249,7 +1246,6 @@ fn build_session_(
12491246
print_fuel,
12501247
jobserver: jobserver::client(),
12511248
has_global_allocator: Once::new(),
1252-
has_panic_handler: Once::new(),
12531249
driver_lint_caps,
12541250
trait_methods_not_found: Lock::new(Default::default()),
12551251
confused_type_with_std_module: Lock::new(Default::default()),

src/librustc/ty/context.rs

+5
Original file line numberDiff line numberDiff line change
@@ -3045,4 +3045,9 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
30453045
assert_eq!(cnum, LOCAL_CRATE);
30463046
attr::contains_name(tcx.hir().krate_attrs(), sym::compiler_builtins)
30473047
};
3048+
providers.has_panic_handler = |tcx, cnum| {
3049+
assert_eq!(cnum, LOCAL_CRATE);
3050+
// We want to check if the panic handler was defined in this crate
3051+
tcx.lang_items().panic_impl().map_or(false, |did| did.is_local())
3052+
};
30483053
}

src/librustc_metadata/encoder.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,6 @@ impl<'tcx> EncodeContext<'tcx> {
542542
let attrs = tcx.hir().krate_attrs();
543543
let has_default_lib_allocator = attr::contains_name(&attrs, sym::default_lib_allocator);
544544
let has_global_allocator = *tcx.sess.has_global_allocator.get();
545-
let has_panic_handler = *tcx.sess.has_panic_handler.try_get().unwrap_or(&false);
546545

547546
let root = self.lazy(CrateRoot {
548547
name: tcx.crate_name(LOCAL_CRATE),
@@ -553,7 +552,7 @@ impl<'tcx> EncodeContext<'tcx> {
553552
panic_strategy: tcx.sess.panic_strategy(),
554553
edition: tcx.sess.edition(),
555554
has_global_allocator: has_global_allocator,
556-
has_panic_handler: has_panic_handler,
555+
has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE),
557556
has_default_lib_allocator: has_default_lib_allocator,
558557
plugin_registrar_fn: tcx.plugin_registrar_fn(LOCAL_CRATE).map(|id| id.index),
559558
proc_macro_decls_static: if is_proc_macro {

src/librustc_typeck/check/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1267,11 +1267,6 @@ fn check_fn<'a, 'tcx>(
12671267
if let Some(panic_impl_did) = fcx.tcx.lang_items().panic_impl() {
12681268
if panic_impl_did == fcx.tcx.hir().local_def_id(fn_id) {
12691269
if let Some(panic_info_did) = fcx.tcx.lang_items().panic_info() {
1270-
// at this point we don't care if there are duplicate handlers or if the handler has
1271-
// the wrong signature as this value we'll be used when writing metadata and that
1272-
// only happens if compilation succeeded
1273-
fcx.tcx.sess.has_panic_handler.try_set_same(true);
1274-
12751270
if declared_ret_ty.kind != ty::Never {
12761271
fcx.tcx.sess.span_err(
12771272
decl.output.span(),

0 commit comments

Comments
 (0)