pub struct ConstantEvaluator<'gcx> {
pub gcx: Gcx<'gcx>,
/* private fields */
}Expand description
Evaluates simple constants.
This only supports basic arithmetic and logical operations, and does not support more complex operations like function calls or memory allocation.
This is only supposed to be used for array sizes and other simple constants.
Fields§
§gcx: Gcx<'gcx>Implementations§
Source§impl<'gcx> ConstantEvaluator<'gcx>
impl<'gcx> ConstantEvaluator<'gcx>
Sourcepub fn new(gcx: Gcx<'gcx>) -> ConstantEvaluator<'gcx>
pub fn new(gcx: Gcx<'gcx>) -> ConstantEvaluator<'gcx>
Creates a new constant evaluator.
Sourcepub fn eval(&mut self, expr: &Expr<'_>) -> Result<IntScalar, ErrorGuaranteed>
pub fn eval(&mut self, expr: &Expr<'_>) -> Result<IntScalar, ErrorGuaranteed>
Evaluates the given expression, emitting an error diagnostic if it fails.
Sourcepub fn try_eval(&mut self, expr: &Expr<'_>) -> Result<IntScalar, EvalError>
pub fn try_eval(&mut self, expr: &Expr<'_>) -> Result<IntScalar, EvalError>
Evaluates the given expression, returning an error if it fails.
Sourcepub fn emit_eval_error(
&self,
expr: &Expr<'_>,
err: EvalError,
) -> ErrorGuaranteed
pub fn emit_eval_error( &self, expr: &Expr<'_>, err: EvalError, ) -> ErrorGuaranteed
Emits a diagnostic for the given evaluation error.
Auto Trait Implementations§
impl<'gcx> Freeze for ConstantEvaluator<'gcx>
impl<'gcx> !RefUnwindSafe for ConstantEvaluator<'gcx>
impl<'gcx> Send for ConstantEvaluator<'gcx>
impl<'gcx> Sync for ConstantEvaluator<'gcx>
impl<'gcx> Unpin for ConstantEvaluator<'gcx>
impl<'gcx> !UnwindSafe for ConstantEvaluator<'gcx>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more