Skip to content

Commit 075affa

Browse files
committed
Convert const field extraction to trans::adt
1 parent 59daf76 commit 075affa

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/librustc/middle/trans/consts.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,12 @@ fn const_expr_unchecked(cx: @CrateContext, e: @ast::expr) -> ValueRef {
240240
}
241241
ast::expr_field(base, field, _) => {
242242
let bt = ty::expr_ty(cx.tcx, base);
243+
let brepr = adt::represent_type(cx, bt);
243244
let bv = const_expr(cx, base);
244245
let (bt, bv) = const_autoderef(cx, bt, bv);
245-
do expr::with_field_tys(cx.tcx, bt, None) |_, field_tys| {
246+
do expr::with_field_tys(cx.tcx, bt, None) |discr, field_tys| {
246247
let ix = ty::field_idx_strict(cx.tcx, field, field_tys);
247-
248-
// Note: ideally, we'd use `struct_field()` here instead
249-
// of hardcoding [0, ix], but we can't because it yields
250-
// the wrong type and also inserts an extra 0 that is
251-
// not needed in the constant variety:
252-
const_get_elt(cx, bv, [0, ix as c_uint])
248+
adt::const_get_element(cx, &brepr, bv, discr, ix)
253249
}
254250
}
255251

0 commit comments

Comments
 (0)