1
Fork 0

Enums in offset_of: update based on est31, scottmcm & llogiq review

This commit is contained in:
George Bateman 2023-08-15 22:32:55 +01:00
parent e936416a8d
commit d995bd61e7
No known key found for this signature in database
GPG key ID: C417AA9C4039EFCF
15 changed files with 150 additions and 140 deletions

View file

@ -248,8 +248,6 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
}
fn handle_offset_of(&mut self, expr: &'tcx hir::Expr<'tcx>) {
use rustc_target::abi::OffsetOfIdx::*;
let data = self.typeck_results().offset_of_data();
let &(container, ref indices) =
data.get(expr.hir_id).expect("no offset_of_data for offset_of");
@ -258,22 +256,10 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
let param_env = self.tcx.param_env(body_did);
let mut current_ty = container;
let mut indices = indices.into_iter();
while let Some(&index) = indices.next() {
match (current_ty.kind(), index) {
(ty::Adt(def, subst), Field(field)) if !def.is_enum() => {
let field = &def.non_enum_variant().fields[field];
self.insert_def_id(field.did);
let field_ty = field.ty(self.tcx, subst);
current_ty = self.tcx.normalize_erasing_regions(param_env, field_ty);
}
(ty::Adt(def, subst), Variant(variant)) if def.is_enum() => {
let Some(&Field(field)) = indices.next() else {
span_bug!(expr.span, "variant must be followed by field in offset_of")
};
for &(variant, field) in indices {
match current_ty.kind() {
ty::Adt(def, subst) => {
let field = &def.variant(variant).fields[field];
self.insert_def_id(field.did);
@ -283,12 +269,11 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
}
// we don't need to mark tuple fields as live,
// but we may need to mark subfields
(ty::Tuple(tys), Field(field)) => {
ty::Tuple(tys) => {
current_ty =
self.tcx.normalize_erasing_regions(param_env, tys[field.as_usize()]);
}
(_, Field(_)) => span_bug!(expr.span, "named field access on non-ADT"),
(_, Variant(_)) => span_bug!(expr.span, "enum variant access on non-enum"),
_ => span_bug!(expr.span, "named field access on non-ADT"),
}
}
}