Skip to content

Commit

Permalink
Group the try_eval functions before the eval functions
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jul 16, 2020
1 parent ef66bf0 commit 1bf0993
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/librustc_middle/ty/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ impl<'tcx> Const<'tcx> {
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]
/// Tries to evaluate the constant if it is `Unevaluated`. If that doesn't succeed, return the
/// unevaluated constant.
Expand All @@ -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]
/// 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 {
Expand Down

0 comments on commit 1bf0993

Please sign in to comment.