diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 7d1cc81e21f65..b9d1a0c10d3d0 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -658,6 +658,12 @@ fn check_item<'tcx>( // global_asm! is always live. worklist.push((id.owner_id.def_id, ComesFromAllowExpect::No)); } + DefKind::Const => { + let item = tcx.hir().item(id); + if let hir::ItemKind::Const(_, _, body_id) = item.kind { + worklist.push((tcx.hir().body_owner_def_id(body_id), ComesFromAllowExpect::No)); + } + } _ => {} } }