Move eval_discriminant.
This commit is contained in:
parent
0e68cbd45d
commit
629cdb42d3
@ -70,22 +70,6 @@ struct ConstAnalysis<'a, 'tcx> {
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
}
|
||||
|
||||
impl<'tcx> ConstAnalysis<'_, 'tcx> {
|
||||
fn eval_discriminant(
|
||||
&self,
|
||||
enum_ty: Ty<'tcx>,
|
||||
variant_index: VariantIdx,
|
||||
) -> Option<ScalarTy<'tcx>> {
|
||||
if !enum_ty.is_enum() {
|
||||
return None;
|
||||
}
|
||||
let discr = enum_ty.discriminant_for_variant(self.tcx, variant_index)?;
|
||||
let discr_layout = self.tcx.layout_of(self.param_env.and(discr.ty)).ok()?;
|
||||
let discr_value = Scalar::try_from_uint(discr.val, discr_layout.size)?;
|
||||
Some(ScalarTy(discr_value, discr.ty))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
|
||||
type Value = FlatSet<ScalarTy<'tcx>>;
|
||||
|
||||
@ -377,6 +361,20 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn eval_discriminant(
|
||||
&self,
|
||||
enum_ty: Ty<'tcx>,
|
||||
variant_index: VariantIdx,
|
||||
) -> Option<ScalarTy<'tcx>> {
|
||||
if !enum_ty.is_enum() {
|
||||
return None;
|
||||
}
|
||||
let discr = enum_ty.discriminant_for_variant(self.tcx, variant_index)?;
|
||||
let discr_layout = self.tcx.layout_of(self.param_env.and(discr.ty)).ok()?;
|
||||
let discr_value = Scalar::try_from_uint(discr.val, discr_layout.size)?;
|
||||
Some(ScalarTy(discr_value, discr.ty))
|
||||
}
|
||||
|
||||
fn wrap_scalar(&self, scalar: Scalar, ty: Ty<'tcx>) -> FlatSet<ScalarTy<'tcx>> {
|
||||
FlatSet::Elem(ScalarTy(scalar, ty))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user