@@ -459,30 +459,32 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
459
459
}
460
460
461
461
fn has_allow_dead_code_or_lang_attr ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> bool {
462
- if tcx. has_attr ( def_id. to_def_id ( ) , sym:: lang) {
463
- return true ;
462
+ fn has_lang_attr ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> bool {
463
+ tcx. has_attr ( def_id. to_def_id ( ) , sym:: lang)
464
+ // Stable attribute for #[lang = "panic_impl"]
465
+ || tcx. has_attr ( def_id. to_def_id ( ) , sym:: panic_handler)
464
466
}
465
467
466
- // Stable attribute for #[lang = "panic_impl"]
467
- if tcx. has_attr ( def_id . to_def_id ( ) , sym :: panic_handler ) {
468
- return true ;
468
+ fn has_allow_dead_code ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> bool {
469
+ let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id ) ;
470
+ tcx . lint_level_at_node ( lint :: builtin :: DEAD_CODE , hir_id ) . 0 == lint :: Allow
469
471
}
470
472
471
- if tcx. def_kind ( def_id) . has_codegen_attrs ( ) {
472
- let cg_attrs = tcx. codegen_fn_attrs ( def_id) ;
473
+ fn has_used_like_attr ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> bool {
474
+ tcx. def_kind ( def_id) . has_codegen_attrs ( ) && {
475
+ let cg_attrs = tcx. codegen_fn_attrs ( def_id) ;
473
476
474
- // #[used], #[no_mangle], #[export_name], etc also keeps the item alive
475
- // forcefully, e.g., for placing it in a specific section.
476
- if cg_attrs. contains_extern_indicator ( )
477
- || cg_attrs. flags . contains ( CodegenFnAttrFlags :: USED )
478
- || cg_attrs. flags . contains ( CodegenFnAttrFlags :: USED_LINKER )
479
- {
480
- return true ;
477
+ // #[used], #[no_mangle], #[export_name], etc also keeps the item alive
478
+ // forcefully, e.g., for placing it in a specific section.
479
+ cg_attrs. contains_extern_indicator ( )
480
+ || cg_attrs. flags . contains ( CodegenFnAttrFlags :: USED )
481
+ || cg_attrs. flags . contains ( CodegenFnAttrFlags :: USED_LINKER )
481
482
}
482
483
}
483
484
484
- let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id) ;
485
- tcx. lint_level_at_node ( lint:: builtin:: DEAD_CODE , hir_id) . 0 == lint:: Allow
485
+ has_allow_dead_code ( tcx, def_id)
486
+ || has_used_like_attr ( tcx, def_id)
487
+ || has_lang_attr ( tcx, def_id)
486
488
}
487
489
488
490
// These check_* functions seeds items that
0 commit comments