1
Fork 0

Extend HIR WF checking to fields

This commit is contained in:
Aaron Hill 2021-07-20 10:56:33 -05:00
parent f913a4fe90
commit 0ebd6e4891
No known key found for this signature in database
GPG key ID: B4087E510E98B164
6 changed files with 15 additions and 13 deletions

View file

@ -523,8 +523,7 @@ fn check_type_defn<'tcx, F>(
fcx.register_wf_obligation(
field.ty.into(),
field.span,
// We don't have an HIR id for the field
ObligationCauseCode::WellFormed(None),
ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(field.def_id))),
)
}
@ -1467,6 +1466,7 @@ struct AdtVariant<'tcx> {
struct AdtField<'tcx> {
ty: Ty<'tcx>,
def_id: LocalDefId,
span: Span,
}
@ -1477,11 +1477,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.fields()
.iter()
.map(|field| {
let field_ty = self.tcx.type_of(self.tcx.hir().local_def_id(field.hir_id));
let def_id = self.tcx.hir().local_def_id(field.hir_id);
let field_ty = self.tcx.type_of(def_id);
let field_ty = self.normalize_associated_types_in(field.ty.span, field_ty);
let field_ty = self.resolve_vars_if_possible(field_ty);
debug!("non_enum_variant: type of field {:?} is {:?}", field, field_ty);
AdtField { ty: field_ty, span: field.ty.span }
AdtField { ty: field_ty, span: field.ty.span, def_id }
})
.collect();
AdtVariant { fields, explicit_discr: None }

View file

@ -25,7 +25,7 @@ fn diagnostic_hir_wf_check<'tcx>(
WellFormedLoc::Ty(def_id) => def_id,
WellFormedLoc::Param { function, param_idx: _ } => function,
};
let hir_id = HirId::make_owner(def_id);
let hir_id = hir.local_def_id_to_hir_id(def_id);
// HIR wfcheck should only ever happen as part of improving an existing error
tcx.sess
@ -140,6 +140,7 @@ fn diagnostic_hir_wf_check<'tcx>(
}
ref item => bug!("Unexpected item {:?}", item),
},
hir::Node::Field(field) => Some(field.ty),
ref node => bug!("Unexpected node {:?}", node),
},
WellFormedLoc::Param { function: _, param_idx } => {