Skip to content

Commit

Permalink
Make check_match and check_liveness take a LocalDefId
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Apr 21, 2023
1 parent 1ce80e2 commit 5bb58a6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}

Expand Down Expand Up @@ -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 }
}

Expand Down
17 changes: 6 additions & 11 deletions compiler/rustc_passes/src/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -137,27 +137,22 @@ 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)
{
return;
}

// 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);

Expand All @@ -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);

Expand Down

0 comments on commit 5bb58a6

Please sign in to comment.