This commit is contained in:
DrMeepster 2023-04-16 14:44:09 -07:00
parent 631ea7cc15
commit 2bcb018253
3 changed files with 12 additions and 13 deletions

View File

@ -255,16 +255,13 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
self.insert_def_id(field.did); self.insert_def_id(field.did);
let field_ty = field.ty(self.tcx, subst); let field_ty = field.ty(self.tcx, subst);
current_ty = current_ty = self.tcx.normalize_erasing_regions(param_env, field_ty);
self.tcx.normalize_erasing_regions(param_env, field_ty);
} }
// we don't need to mark tuple fields as live, // we don't need to mark tuple fields as live,
// but we may need to mark subfields // but we may need to mark subfields
ty::Tuple(tys) => { ty::Tuple(tys) => {
current_ty = self.tcx.normalize_erasing_regions( current_ty =
param_env, self.tcx.normalize_erasing_regions(param_env, tys[index.as_usize()]);
tys[index.as_usize()],
);
} }
_ => span_bug!(expr.span, "named field access on non-ADT"), _ => span_bug!(expr.span, "named field access on non-ADT"),
} }

View File

@ -27,11 +27,13 @@ fn test<T>() -> usize
where where
GenericIsEqual<T>: Project<EquateParamTo = MyFieldIsNotDead>, GenericIsEqual<T>: Project<EquateParamTo = MyFieldIsNotDead>,
{ {
// The first field of the A that we construct here is `<GenericIsEqual<T>> as Project>::EquateParamTo`. // The first field of the A that we construct here is
// Typeck normalizes this and figures that the not_dead field is totally fine and accessible. // `<GenericIsEqual<T>> as Project>::EquateParamTo`.
// But importantly, the normalization ends up with T, which, as we've declared in our param env is MyFieldDead. // Typeck normalizes this and figures that the not_dead field is totally fine and accessible.
// When we're in the param env of the `a` field, the where bound above is not in scope, so we don't know what T is - it's generic. // But importantly, the normalization ends up with T, which, as we've declared in our param
// We cannot access a field on T. Boom! // env is MyFieldDead. When we're in the param env of the `a` field, the where bound above
// is not in scope, so we don't know what T is - it's generic.
// We cannot access a field on T. Boom!
std::mem::offset_of!(A<GenericIsEqual<T>>, a.not_dead) std::mem::offset_of!(A<GenericIsEqual<T>>, a.not_dead)
} }