2024-06-30 19:31:15 +01:00
|
|
|
use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId};
|
|
|
|
|
use rustc_hir::intravisit;
|
2024-11-28 22:04:03 -08:00
|
|
|
use rustc_middle::hir::nested_filter;
|
2024-06-19 13:11:18 +02:00
|
|
|
use rustc_middle::ty::TyCtxt;
|
|
|
|
|
use rustc_span::sym;
|
|
|
|
|
|
|
|
|
|
pub(crate) fn opaque_hidden_types(tcx: TyCtxt<'_>) {
|
|
|
|
|
if !tcx.has_attr(CRATE_DEF_ID, sym::rustc_hidden_type_of_opaques) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-09 20:43:30 -07:00
|
|
|
for id in tcx.hir_crate_items(()).opaques() {
|
|
|
|
|
let ty = tcx.type_of(id).instantiate_identity();
|
|
|
|
|
let span = tcx.def_span(id);
|
|
|
|
|
tcx.dcx().emit_err(crate::errors::TypeOf { span, ty });
|
2024-06-19 13:11:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2024-06-19 14:24:25 +02:00
|
|
|
|
|
|
|
|
pub(crate) fn predicates_and_item_bounds(tcx: TyCtxt<'_>) {
|
|
|
|
|
for id in tcx.hir_crate_items(()).owners() {
|
|
|
|
|
if tcx.has_attr(id, sym::rustc_dump_predicates) {
|
|
|
|
|
let preds = tcx.predicates_of(id).instantiate_identity(tcx).predicates;
|
|
|
|
|
let span = tcx.def_span(id);
|
|
|
|
|
|
|
|
|
|
let mut diag = tcx.dcx().struct_span_err(span, sym::rustc_dump_predicates.as_str());
|
|
|
|
|
for pred in preds {
|
|
|
|
|
diag.note(format!("{pred:?}"));
|
|
|
|
|
}
|
|
|
|
|
diag.emit();
|
|
|
|
|
}
|
|
|
|
|
if tcx.has_attr(id, sym::rustc_dump_item_bounds) {
|
|
|
|
|
let bounds = tcx.item_bounds(id).instantiate_identity();
|
|
|
|
|
let span = tcx.def_span(id);
|
|
|
|
|
|
|
|
|
|
let mut diag = tcx.dcx().struct_span_err(span, sym::rustc_dump_item_bounds.as_str());
|
|
|
|
|
for bound in bounds {
|
|
|
|
|
diag.note(format!("{bound:?}"));
|
|
|
|
|
}
|
|
|
|
|
diag.emit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-30 19:31:15 +01:00
|
|
|
|
|
|
|
|
pub(crate) fn def_parents(tcx: TyCtxt<'_>) {
|
2024-11-28 22:04:03 -08:00
|
|
|
for iid in tcx.hir().items() {
|
|
|
|
|
let did = iid.owner_id.def_id;
|
2024-06-30 19:31:15 +01:00
|
|
|
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> {
|
2024-11-28 22:04:03 -08:00
|
|
|
type NestedFilter = nested_filter::All;
|
2024-06-30 19:31:15 +01:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-28 22:04:03 -08:00
|
|
|
// Look for any anon consts inside of this item as there is no way to apply
|
2024-06-30 19:31:15 +01:00
|
|
|
// 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![] };
|
2024-11-28 22:04:03 -08:00
|
|
|
intravisit::walk_item(&mut anon_ct_finder, tcx.hir().item(iid));
|
2024-06-30 19:31:15 +01:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|