Skip to content

Commit 1a86a93

Browse files
committed
Rollup merge of #54007 - japaric:gh53964, r=cramertj
crates that provide a `panic_handler` are exempt from the `unused_extern_crates` lint fixes the *first* false positive reported in #53964
2 parents 407da0a + 6c4f3f5 commit 1a86a93

File tree

15 files changed

+65
-9
lines changed

15 files changed

+65
-9
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ define_dep_nodes!( <'tcx>
574574
[] IsPanicRuntime(CrateNum),
575575
[] IsCompilerBuiltins(CrateNum),
576576
[] HasGlobalAllocator(CrateNum),
577+
[] HasPanicHandler(CrateNum),
577578
[input] ExternCrate(DefId),
578579
[eval_always] LintLevels,
579580
[] Specializes { impl1: DefId, impl2: DefId },

src/librustc/session/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ pub struct Session {
159159
/// Metadata about the allocators for the current crate being compiled
160160
pub has_global_allocator: Once<bool>,
161161

162+
/// Metadata about the panic handlers for the current crate being compiled
163+
pub has_panic_handler: Once<bool>,
164+
162165
/// Cap lint level specified by a driver specifically.
163166
pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
164167
}
@@ -1160,6 +1163,7 @@ pub fn build_session_(
11601163
(*GLOBAL_JOBSERVER).clone()
11611164
},
11621165
has_global_allocator: Once::new(),
1166+
has_panic_handler: Once::new(),
11631167
driver_lint_caps: FxHashMap(),
11641168
};
11651169

src/librustc/ty/query/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,12 @@ impl<'tcx> QueryDescription<'tcx> for queries::has_global_allocator<'tcx> {
464464
}
465465
}
466466

467+
impl<'tcx> QueryDescription<'tcx> for queries::has_panic_handler<'tcx> {
468+
fn describe(_: TyCtxt, _: CrateNum) -> String {
469+
"checking if the crate has_panic_handler".to_string()
470+
}
471+
}
472+
467473
impl<'tcx> QueryDescription<'tcx> for queries::extern_crate<'tcx> {
468474
fn describe(_: TyCtxt, _: DefId) -> String {
469475
"getting crate's ExternCrateData".to_string()

src/librustc/ty/query/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ define_queries! { <'tcx>
381381
[fatal_cycle] fn is_panic_runtime: IsPanicRuntime(CrateNum) -> bool,
382382
[fatal_cycle] fn is_compiler_builtins: IsCompilerBuiltins(CrateNum) -> bool,
383383
[fatal_cycle] fn has_global_allocator: HasGlobalAllocator(CrateNum) -> bool,
384+
[fatal_cycle] fn has_panic_handler: HasPanicHandler(CrateNum) -> bool,
384385
[fatal_cycle] fn is_sanitizer_runtime: IsSanitizerRuntime(CrateNum) -> bool,
385386
[fatal_cycle] fn is_profiler_runtime: IsProfilerRuntime(CrateNum) -> bool,
386387
[fatal_cycle] fn panic_strategy: GetPanicStrategy(CrateNum) -> PanicStrategy,

src/librustc/ty/query/plumbing.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
11681168
DepKind::IsPanicRuntime => { force!(is_panic_runtime, krate!()); }
11691169
DepKind::IsCompilerBuiltins => { force!(is_compiler_builtins, krate!()); }
11701170
DepKind::HasGlobalAllocator => { force!(has_global_allocator, krate!()); }
1171+
DepKind::HasPanicHandler => { force!(has_panic_handler, krate!()); }
11711172
DepKind::ExternCrate => { force!(extern_crate, def_id!()); }
11721173
DepKind::LintLevels => { force!(lint_levels, LOCAL_CRATE); }
11731174
DepKind::InScopeTraits => { force!(in_scope_traits_map, def_id!().index); }

src/librustc_metadata/cstore_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
173173
is_panic_runtime => { cdata.root.panic_runtime }
174174
is_compiler_builtins => { cdata.root.compiler_builtins }
175175
has_global_allocator => { cdata.root.has_global_allocator }
176+
has_panic_handler => { cdata.root.has_panic_handler }
176177
is_sanitizer_runtime => { cdata.root.sanitizer_runtime }
177178
is_profiler_runtime => { cdata.root.profiler_runtime }
178179
panic_strategy => { cdata.root.panic_strategy }

src/librustc_metadata/encoder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
484484
let is_proc_macro = tcx.sess.crate_types.borrow().contains(&CrateType::ProcMacro);
485485
let has_default_lib_allocator = attr::contains_name(&attrs, "default_lib_allocator");
486486
let has_global_allocator = *tcx.sess.has_global_allocator.get();
487+
let has_panic_handler = *tcx.sess.has_panic_handler.try_get().unwrap_or(&false);
487488

488489
let root = self.lazy(&CrateRoot {
489490
name: tcx.crate_name(LOCAL_CRATE),
@@ -494,6 +495,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
494495
panic_strategy: tcx.sess.panic_strategy(),
495496
edition: hygiene::default_edition(),
496497
has_global_allocator: has_global_allocator,
498+
has_panic_handler: has_panic_handler,
497499
has_default_lib_allocator: has_default_lib_allocator,
498500
plugin_registrar_fn: tcx.sess
499501
.plugin_registrar_fn

src/librustc_metadata/schema.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ pub struct CrateRoot {
193193
pub panic_strategy: PanicStrategy,
194194
pub edition: Edition,
195195
pub has_global_allocator: bool,
196+
pub has_panic_handler: bool,
196197
pub has_default_lib_allocator: bool,
197198
pub plugin_registrar_fn: Option<DefIndex>,
198199
pub macro_derive_registrar: Option<DefIndex>,

src/librustc_typeck/check/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,11 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
11381138
if let Some(panic_impl_did) = fcx.tcx.lang_items().panic_impl() {
11391139
if panic_impl_did == fcx.tcx.hir.local_def_id(fn_id) {
11401140
if let Some(panic_info_did) = fcx.tcx.lang_items().panic_info() {
1141+
// at this point we don't care if there are duplicate handlers or if the handler has
1142+
// the wrong signature as this value we'll be used when writing metadata and that
1143+
// only happens if compilation succeeded
1144+
fcx.tcx.sess.has_panic_handler.try_set_same(true);
1145+
11411146
if declared_ret_ty.sty != ty::Never {
11421147
fcx.tcx.sess.span_err(
11431148
decl.output.span(),

src/librustc_typeck/check_unused.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) {
117117
!tcx.is_compiler_builtins(cnum)
118118
&& !tcx.is_panic_runtime(cnum)
119119
&& !tcx.has_global_allocator(cnum)
120+
&& !tcx.has_panic_handler(cnum)
120121
})
121122
.cloned()
122123
.collect();

0 commit comments

Comments
 (0)