Skip to content

Commit f6d4098

Browse files
committed
Auto merge of #61723 - RalfJung:no-more-recursive-enums, r=<try>
[DO NOT MERGE] see what breaks when we remove this recursive-enum-discriminants check
2 parents a73ecb3 + ca7c9b1 commit f6d4098

File tree

1 file changed

+2
-81
lines changed

1 file changed

+2
-81
lines changed

src/librustc_mir/hair/cx/expr.rs

+2-81
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::hair::cx::block;
44
use crate::hair::cx::to_ref::ToRef;
55
use crate::hair::util::UserAnnotatedTyHelpers;
66
use rustc_data_structures::indexed_vec::Idx;
7-
use rustc::hir::def::{CtorOf, Res, DefKind, CtorKind};
7+
use rustc::hir::def::{Res, DefKind, CtorKind};
88
use rustc::mir::interpret::{GlobalId, ErrorHandled, ConstValue};
99
use rustc::ty::{self, AdtKind, Ty};
1010
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, AutoBorrowMutability, PointerCast};
@@ -633,86 +633,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
633633
// Convert the lexpr to a vexpr.
634634
ExprKind::Use { source: source.to_ref() }
635635
} else {
636-
// check whether this is casting an enum variant discriminant
637-
// to prevent cycles, we refer to the discriminant initializer
638-
// which is always an integer and thus doesn't need to know the
639-
// enum's layout (or its tag type) to compute it during const eval
640-
// Example:
641-
// enum Foo {
642-
// A,
643-
// B = A as isize + 4,
644-
// }
645-
// The correct solution would be to add symbolic computations to miri,
646-
// so we wouldn't have to compute and store the actual value
647-
let var = if let hir::ExprKind::Path(ref qpath) = source.node {
648-
let res = cx.tables().qpath_res(qpath, source.hir_id);
649-
cx
650-
.tables()
651-
.node_type(source.hir_id)
652-
.ty_adt_def()
653-
.and_then(|adt_def| {
654-
match res {
655-
Res::Def(
656-
DefKind::Ctor(CtorOf::Variant, CtorKind::Const),
657-
variant_ctor_id,
658-
) => {
659-
let idx = adt_def.variant_index_with_ctor_id(variant_ctor_id);
660-
let (d, o) = adt_def.discriminant_def_for_variant(idx);
661-
use rustc::ty::util::IntTypeExt;
662-
let ty = adt_def.repr.discr_type();
663-
let ty = ty.to_ty(cx.tcx());
664-
Some((d, o, ty))
665-
}
666-
_ => None,
667-
}
668-
})
669-
} else {
670-
None
671-
};
672-
673-
let source = if let Some((did, offset, var_ty)) = var {
674-
let mk_const = |literal| Expr {
675-
temp_lifetime,
676-
ty: var_ty,
677-
span: expr.span,
678-
kind: ExprKind::Literal {
679-
literal,
680-
user_ty: None
681-
},
682-
}.to_ref();
683-
let offset = mk_const(ty::Const::from_bits(
684-
cx.tcx,
685-
offset as u128,
686-
cx.param_env.and(var_ty),
687-
));
688-
match did {
689-
Some(did) => {
690-
// in case we are offsetting from a computed discriminant
691-
// and not the beginning of discriminants (which is always `0`)
692-
let substs = InternalSubsts::identity_for_item(cx.tcx(), did);
693-
let lhs = mk_const(cx.tcx().mk_const(ty::Const {
694-
val: ConstValue::Unevaluated(did, substs),
695-
ty: var_ty,
696-
}));
697-
let bin = ExprKind::Binary {
698-
op: BinOp::Add,
699-
lhs,
700-
rhs: offset,
701-
};
702-
Expr {
703-
temp_lifetime,
704-
ty: var_ty,
705-
span: expr.span,
706-
kind: bin,
707-
}.to_ref()
708-
},
709-
None => offset,
710-
}
711-
} else {
712-
source.to_ref()
713-
};
714-
715-
ExprKind::Cast { source }
636+
ExprKind::Cast { source: source.to_ref() }
716637
};
717638

718639
if let Some(user_ty) = user_ty {

0 commit comments

Comments
 (0)