Make check_match and check_liveness take a LocalDefId

This commit is contained in:
Oli Scherer 2023-02-16 09:34:53 +00:00
parent 1ce80e210d
commit 5bb58a68de
3 changed files with 9 additions and 14 deletions

View File

@ -775,7 +775,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
// "not all control paths return a value" is reported here.
//
// maybe move the check to a MIR pass?
tcx.ensure().check_liveness(def_id.to_def_id());
tcx.ensure().check_liveness(def_id);
});
});
}

View File

@ -832,7 +832,7 @@ rustc_queries! {
desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
}
query check_liveness(key: DefId) {
query check_liveness(key: LocalDefId) {
desc { |tcx| "checking liveness of variables in `{}`", tcx.def_path_str(key) }
}
@ -1021,7 +1021,7 @@ rustc_queries! {
}
query check_match(key: LocalDefId) {
desc { |tcx| "match-checking `{}`", tcx.def_path_str(key.to_def_id()) }
desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
cache_on_disk_if { true }
}

View File

@ -90,7 +90,7 @@ use rustc_errors::Applicability;
use rustc_errors::Diagnostic;
use rustc_hir as hir;
use rustc_hir::def::*;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{Expr, HirId, HirIdMap, HirIdSet};
use rustc_index::vec::IndexVec;
@ -137,14 +137,9 @@ fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt<'_>) -> String {
}
}
fn check_liveness(tcx: TyCtxt<'_>, def_id: DefId) {
let local_def_id = match def_id.as_local() {
None => return,
Some(def_id) => def_id,
};
fn check_liveness(tcx: TyCtxt<'_>, def_id: LocalDefId) {
// Don't run unused pass for #[derive()]
let parent = tcx.local_parent(local_def_id);
let parent = tcx.local_parent(def_id);
if let DefKind::Impl { .. } = tcx.def_kind(parent)
&& tcx.has_attr(parent, sym::automatically_derived)
{
@ -152,12 +147,12 @@ fn check_liveness(tcx: TyCtxt<'_>, def_id: DefId) {
}
// Don't run unused pass for #[naked]
if tcx.has_attr(def_id, sym::naked) {
if tcx.has_attr(def_id.to_def_id(), sym::naked) {
return;
}
let mut maps = IrMaps::new(tcx);
let body_id = tcx.hir().body_owned_by(local_def_id);
let body_id = tcx.hir().body_owned_by(def_id);
let hir_id = tcx.hir().body_owner(body_id);
let body = tcx.hir().body(body_id);
@ -173,7 +168,7 @@ fn check_liveness(tcx: TyCtxt<'_>, def_id: DefId) {
maps.visit_body(body);
// compute liveness
let mut lsets = Liveness::new(&mut maps, local_def_id);
let mut lsets = Liveness::new(&mut maps, def_id);
let entry_ln = lsets.compute(&body, hir_id);
lsets.log_liveness(entry_ln, body_id.hir_id);