diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2023-01-30 10:53:11 +0000 |
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2023-01-30 10:53:11 +0000 |
| commit | d4585408dc28b7d03a38aa29a0394e9e7ef2de69 (patch) | |
| tree | 65ff606f8bc1cc74bbc8f2c6eef45efe219dc433 /compiler/rustc_passes | |
| parent | f55b0022db8dccc6aa6bf3f650b562eaec0fdc54 (diff) | |
| download | rust-d4585408dc28b7d03a38aa29a0394e9e7ef2de69.tar.gz rust-d4585408dc28b7d03a38aa29a0394e9e7ef2de69.zip | |
Split `has_allow_dead_code_or_lang_attr` into sub functions
Diffstat (limited to 'compiler/rustc_passes')
| -rw-r--r-- | compiler/rustc_passes/src/dead.rs | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 127acb46e92..c061787c30d 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -459,30 +459,32 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> { } fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { - if tcx.has_attr(def_id.to_def_id(), sym::lang) { - return true; + fn has_lang_attr(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { + tcx.has_attr(def_id.to_def_id(), sym::lang) + // Stable attribute for #[lang = "panic_impl"] + || tcx.has_attr(def_id.to_def_id(), sym::panic_handler) } - // Stable attribute for #[lang = "panic_impl"] - if tcx.has_attr(def_id.to_def_id(), sym::panic_handler) { - return true; + fn has_allow_dead_code(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); + tcx.lint_level_at_node(lint::builtin::DEAD_CODE, hir_id).0 == lint::Allow } - if tcx.def_kind(def_id).has_codegen_attrs() { - let cg_attrs = tcx.codegen_fn_attrs(def_id); + fn has_used_like_attr(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { + tcx.def_kind(def_id).has_codegen_attrs() && { + let cg_attrs = tcx.codegen_fn_attrs(def_id); - // #[used], #[no_mangle], #[export_name], etc also keeps the item alive - // forcefully, e.g., for placing it in a specific section. - if cg_attrs.contains_extern_indicator() - || cg_attrs.flags.contains(CodegenFnAttrFlags::USED) - || cg_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER) - { - return true; + // #[used], #[no_mangle], #[export_name], etc also keeps the item alive + // forcefully, e.g., for placing it in a specific section. + cg_attrs.contains_extern_indicator() + || cg_attrs.flags.contains(CodegenFnAttrFlags::USED) + || cg_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER) } } - let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); - tcx.lint_level_at_node(lint::builtin::DEAD_CODE, hir_id).0 == lint::Allow + has_lang_attr(tcx, def_id) + || has_used_like_attr(tcx, def_id) + || has_allow_dead_code(tcx, def_id) } // These check_* functions seeds items that |
