AST/HIR: Merge field access expressions for named and numeric fields

This commit is contained in:
Vadim Petrochenkov 2018-04-01 21:48:39 +03:00
parent 6c537493d0
commit 44acea4d88
43 changed files with 105 additions and 432 deletions

View file

@ -584,6 +584,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
hir::ExprField(ref source, name) => {
let index = match cx.tables().expr_ty_adjusted(source).sty {
ty::TyAdt(adt_def, _) => adt_def.variants[0].index_of_field_named(name.node),
ty::TyTuple(..) => name.node.as_str().parse::<usize>().ok(),
ref ty => span_bug!(expr.span, "field of non-ADT: {:?}", ty),
};
let index =
@ -595,12 +596,6 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
name: Field::new(index),
}
}
hir::ExprTupField(ref source, index) => {
ExprKind::Field {
lhs: source.to_ref(),
name: Field::new(index.node as usize),
}
}
hir::ExprCast(ref source, _) => {
// Check to see if this cast is a "coercion cast", where the cast is actually done
// using a coercion (or is a no-op).