Move eval_discriminant.
This commit is contained in:
parent
0e68cbd45d
commit
629cdb42d3
1 changed files with 14 additions and 16 deletions
|
@ -70,22 +70,6 @@ struct ConstAnalysis<'a, 'tcx> {
|
||||||
param_env: ty::ParamEnv<'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> {
|
impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
|
||||||
type Value = FlatSet<ScalarTy<'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>> {
|
fn wrap_scalar(&self, scalar: Scalar, ty: Ty<'tcx>) -> FlatSet<ScalarTy<'tcx>> {
|
||||||
FlatSet::Elem(ScalarTy(scalar, ty))
|
FlatSet::Elem(ScalarTy(scalar, ty))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue