Actually walk fields of Adt definitions

This commit is contained in:
Oli Scherer 2024-02-07 14:05:34 +00:00
parent 0b97d18f71
commit b998b515e9

View File

@ -4,7 +4,7 @@
use std::ops::ControlFlow; use std::ops::ControlFlow;
use rustc_hir::{def::DefKind, def_id::LocalDefId}; use rustc_hir::{def::DefKind, def_id::LocalDefId};
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::{self, TyCtxt};
use rustc_span::Span; use rustc_span::Span;
use rustc_type_ir::visit::TypeVisitable; use rustc_type_ir::visit::TypeVisitable;
@ -58,7 +58,16 @@ pub(crate) fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
// Look at field types // Look at field types
DefKind::Struct | DefKind::Union | DefKind::Enum => { DefKind::Struct | DefKind::Union | DefKind::Enum => {
let span = tcx.def_ident_span(item).unwrap(); let span = tcx.def_ident_span(item).unwrap();
visitor.visit(span, tcx.type_of(item).instantiate_identity()); let ty = tcx.type_of(item).instantiate_identity();
visitor.visit(span, ty);
let ty::Adt(def, args) = ty.kind() else {
span_bug!(span, "invalid type for {kind:?}: {:#?}", ty.kind())
};
for field in def.all_fields() {
let span = tcx.def_ident_span(field.did).unwrap();
let ty = field.ty(tcx, args);
visitor.visit(span, ty);
}
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) { for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
visitor.visit(span, pred)?; visitor.visit(span, pred)?;
} }