add rustc_dump_def_parents
attribute
This commit is contained in:
parent
6c3485512f
commit
552794410a
6 changed files with 217 additions and 1 deletions
|
@ -1,5 +1,7 @@
|
|||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::CRATE_DEF_ID;
|
||||
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
|
||||
use rustc_hir::intravisit;
|
||||
use rustc_middle::hir::nested_filter::OnlyBodies;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::sym;
|
||||
|
||||
|
@ -41,3 +43,49 @@ pub(crate) fn predicates_and_item_bounds(tcx: TyCtxt<'_>) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn def_parents(tcx: TyCtxt<'_>) {
|
||||
for did in tcx.hir().body_owners() {
|
||||
if tcx.has_attr(did, sym::rustc_dump_def_parents) {
|
||||
struct AnonConstFinder<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
anon_consts: Vec<LocalDefId>,
|
||||
}
|
||||
|
||||
impl<'tcx> intravisit::Visitor<'tcx> for AnonConstFinder<'tcx> {
|
||||
type NestedFilter = OnlyBodies;
|
||||
|
||||
fn nested_visit_map(&mut self) -> Self::Map {
|
||||
self.tcx.hir()
|
||||
}
|
||||
|
||||
fn visit_anon_const(&mut self, c: &'tcx rustc_hir::AnonConst) {
|
||||
self.anon_consts.push(c.def_id);
|
||||
intravisit::walk_anon_const(self, c)
|
||||
}
|
||||
}
|
||||
|
||||
// Look for any anon consts inside of this body owner as there is no way to apply
|
||||
// the `rustc_dump_def_parents` attribute to the anon const so it would not be possible
|
||||
// to see what its def parent is.
|
||||
let mut anon_ct_finder = AnonConstFinder { tcx, anon_consts: vec![] };
|
||||
intravisit::walk_expr(&mut anon_ct_finder, tcx.hir().body_owned_by(did).value);
|
||||
|
||||
for did in [did].into_iter().chain(anon_ct_finder.anon_consts) {
|
||||
let span = tcx.def_span(did);
|
||||
|
||||
let mut diag = tcx.dcx().struct_span_err(
|
||||
span,
|
||||
format!("{}: {did:?}", sym::rustc_dump_def_parents.as_str()),
|
||||
);
|
||||
|
||||
let mut current_did = did.to_def_id();
|
||||
while let Some(parent_did) = tcx.opt_parent(current_did) {
|
||||
current_did = parent_did;
|
||||
diag.span_note(tcx.def_span(parent_did), format!("{parent_did:?}"));
|
||||
}
|
||||
diag.emit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,6 +169,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
|
|||
tcx.sess.time("variance_dumping", || variance::dump::variances(tcx));
|
||||
collect::dump::opaque_hidden_types(tcx);
|
||||
collect::dump::predicates_and_item_bounds(tcx);
|
||||
collect::dump::def_parents(tcx);
|
||||
}
|
||||
|
||||
// Make sure we evaluate all static and (non-associated) const items, even if unused.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue