pub trait ConstantExt<'tcx>: Sized + Debug {
// Required method
fn eval_constant<S: UnderOwnerState<'tcx>>(&self, s: &S) -> Option<Self>;
// Provided method
fn translate_uneval(
&self,
s: &impl UnderOwnerState<'tcx>,
ucv: UnevaluatedConst<'tcx>,
span: Span,
) -> TranslateUnevalRes<Self> { ... }
}
Required Methods§
fn eval_constant<S: UnderOwnerState<'tcx>>(&self, s: &S) -> Option<Self>
Provided Methods§
sourcefn translate_uneval(
&self,
s: &impl UnderOwnerState<'tcx>,
ucv: UnevaluatedConst<'tcx>,
span: Span,
) -> TranslateUnevalRes<Self>
fn translate_uneval( &self, s: &impl UnderOwnerState<'tcx>, ucv: UnevaluatedConst<'tcx>, span: Span, ) -> TranslateUnevalRes<Self>
Performs a one-step translation of a constant.
- When a constant refers to a named top-level constant, we want to use that, thus we translate the constant to a
ConstantExprKind::GlobalName
. This is captured by the variantTranslateUnevalRes::GlobalName
. - When a constant refers to a anonymous top-level constant, we evaluate it. If the evaluation fails, we report an error: we expect every AnonConst to be reducible. Otherwise, we return the variant
TranslateUnevalRes::EvaluatedConstant
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.