Skip to main content

ConstExt

Trait ConstExt 

Source
pub trait ConstExt<'tcx> {
Show 14 methods // Required methods fn from_bits( tcx: TyCtxt<'tcx>, bits: u128, typing_env: TypingEnv<'tcx>, ty: Ty<'tcx>, ) -> Self; fn zero_sized(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self; fn new_value( tcx: TyCtxt<'tcx>, valtree: ValTree<'tcx>, ty: Ty<'tcx>, ) -> Const<'tcx>; fn from_bool(tcx: TyCtxt<'tcx>, v: bool) -> Self; fn from_target_usize(tcx: TyCtxt<'tcx>, n: u64) -> Self; fn to_value(self) -> Value<'tcx>; fn try_to_value(self) -> Option<Value<'tcx>>; fn to_leaf(self) -> ScalarInt; fn to_branch(self) -> &'tcx [Const<'tcx>] ; fn try_to_leaf(self) -> Option<ScalarInt>; fn try_to_scalar(self) -> Option<Scalar>; fn try_to_branch(self) -> Option<&'tcx [Const<'tcx>]>; fn try_to_target_usize(self, tcx: TyCtxt<'tcx>) -> Option<u64>; fn walk(self) -> TypeWalker<TyCtxt<'tcx>> ;
}

Required Methods§

Source

fn from_bits( tcx: TyCtxt<'tcx>, bits: u128, typing_env: TypingEnv<'tcx>, ty: Ty<'tcx>, ) -> Self

Creates a constant with the given integer value and interns it.

Source

fn zero_sized(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self

Creates an interned zst constant.

Source

fn new_value( tcx: TyCtxt<'tcx>, valtree: ValTree<'tcx>, ty: Ty<'tcx>, ) -> Const<'tcx>

Source

fn from_bool(tcx: TyCtxt<'tcx>, v: bool) -> Self

Creates an interned bool constant.

Source

fn from_target_usize(tcx: TyCtxt<'tcx>, n: u64) -> Self

Creates an interned usize constant.

Source

fn to_value(self) -> Value<'tcx>

Panics if self.kind != ty::ConstKind::Value.

Source

fn try_to_value(self) -> Option<Value<'tcx>>

Attempts to convert to a value.

Note that this does not normalize the constant.

Source

fn to_leaf(self) -> ScalarInt

Converts to a ValTreeKind::Leaf value, panic’ing if this constant is some other kind.

Note that this does not normalize the constant.

Source

fn to_branch(self) -> &'tcx [Const<'tcx>]

Converts to a ValTreeKind::Branch value, panic’ing if this constant is some other kind.

Note that this does not normalize the constant.

Source

fn try_to_leaf(self) -> Option<ScalarInt>

Attempts to convert to a ValTreeKind::Leaf value.

Note that this does not normalize the constant.

Source

fn try_to_scalar(self) -> Option<Scalar>

Attempts to convert to a ValTreeKind::Leaf value.

Note that this does not normalize the constant.

Source

fn try_to_branch(self) -> Option<&'tcx [Const<'tcx>]>

Attempts to convert to a ValTreeKind::Branch value.

Note that this does not normalize the constant.

Source

fn try_to_target_usize(self, tcx: TyCtxt<'tcx>) -> Option<u64>

Convenience method to extract the value of a usize constant, useful to get the length of an array type.

Note that this does not evaluate the constant.

Source

fn walk(self) -> TypeWalker<TyCtxt<'tcx>>

Iterator that walks self and any types reachable from self, in depth-first order. Note that just walks the types that appear in self, it does not descend into the fields of structs or variants. For example:

isize => { isize }
Foo<Bar<isize>> => { Foo<Bar<isize>>, Bar<isize>, isize }
[isize] => { [isize], isize }

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<'tcx> ConstExt<'tcx> for Const<'tcx>