diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 13b76b79b3d82..403b32df20e10 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -148,9 +148,6 @@ pub struct Session { /// Metadata about the allocators for the current crate being compiled. pub has_global_allocator: Once, - /// Metadata about the panic handlers for the current crate being compiled. - pub has_panic_handler: Once, - /// Cap lint level specified by a driver specifically. pub driver_lint_caps: FxHashMap, @@ -1211,7 +1208,6 @@ fn build_session_( print_fuel, jobserver: jobserver::client(), has_global_allocator: Once::new(), - has_panic_handler: Once::new(), driver_lint_caps, trait_methods_not_found: Lock::new(Default::default()), confused_type_with_std_module: Lock::new(Default::default()), diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 3d28beefb3413..0906d9ebd8e7f 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -3045,4 +3045,9 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) { assert_eq!(cnum, LOCAL_CRATE); attr::contains_name(tcx.hir().krate_attrs(), sym::compiler_builtins) }; + providers.has_panic_handler = |tcx, cnum| { + assert_eq!(cnum, LOCAL_CRATE); + // We want to check if the panic handler was defined in this crate + tcx.lang_items().panic_impl().map_or(false, |did| did.is_local()) + }; } diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index f2b0cfa530508..de00e9920e683 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -542,7 +542,6 @@ impl<'tcx> EncodeContext<'tcx> { let attrs = tcx.hir().krate_attrs(); let has_default_lib_allocator = attr::contains_name(&attrs, sym::default_lib_allocator); let has_global_allocator = *tcx.sess.has_global_allocator.get(); - let has_panic_handler = *tcx.sess.has_panic_handler.try_get().unwrap_or(&false); let root = self.lazy(CrateRoot { name: tcx.crate_name(LOCAL_CRATE), @@ -553,7 +552,7 @@ impl<'tcx> EncodeContext<'tcx> { panic_strategy: tcx.sess.panic_strategy(), edition: tcx.sess.edition(), has_global_allocator: has_global_allocator, - has_panic_handler: has_panic_handler, + has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE), has_default_lib_allocator: has_default_lib_allocator, plugin_registrar_fn: tcx.plugin_registrar_fn(LOCAL_CRATE).map(|id| id.index), proc_macro_decls_static: if is_proc_macro { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index a2af29aef094b..ee0fe48cc8b9f 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1267,11 +1267,6 @@ fn check_fn<'a, 'tcx>( if let Some(panic_impl_did) = fcx.tcx.lang_items().panic_impl() { if panic_impl_did == fcx.tcx.hir().local_def_id(fn_id) { if let Some(panic_info_did) = fcx.tcx.lang_items().panic_info() { - // at this point we don't care if there are duplicate handlers or if the handler has - // the wrong signature as this value we'll be used when writing metadata and that - // only happens if compilation succeeded - fcx.tcx.sess.has_panic_handler.try_set_same(true); - if declared_ret_ty.kind != ty::Never { fcx.tcx.sess.span_err( decl.output.span(),