Group the try_eval functions before the eval functions

This commit is contained in:
Oliver Scherer 2020-07-13 19:07:37 +02:00
parent ef66bf067b
commit 1bf09933ed

View File

@ -163,6 +163,16 @@ impl<'tcx> Const<'tcx> {
self.val.eval(tcx, param_env).try_to_bits(size) self.val.eval(tcx, param_env).try_to_bits(size)
} }
#[inline]
pub fn try_eval_bool(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Option<bool> {
self.val.eval(tcx, param_env).try_to_bool()
}
#[inline]
pub fn try_eval_usize(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Option<u64> {
self.val.eval(tcx, param_env).try_to_machine_usize(tcx)
}
#[inline] #[inline]
/// Tries to evaluate the constant if it is `Unevaluated`. If that doesn't succeed, return the /// Tries to evaluate the constant if it is `Unevaluated`. If that doesn't succeed, return the
/// unevaluated constant. /// unevaluated constant.
@ -177,16 +187,6 @@ impl<'tcx> Const<'tcx> {
} }
} }
#[inline]
pub fn try_eval_bool(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Option<bool> {
self.val.eval(tcx, param_env).try_to_bool()
}
#[inline]
pub fn try_eval_usize(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Option<u64> {
self.val.eval(tcx, param_env).try_to_machine_usize(tcx)
}
#[inline] #[inline]
/// Panics if the value cannot be evaluated or doesn't contain a valid integer of the given type. /// Panics if the value cannot be evaluated or doesn't contain a valid integer of the given type.
pub fn eval_bits(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>) -> u128 { pub fn eval_bits(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>) -> u128 {