Skip to main content

Const

Type Alias Const 

Source
pub type Const<'tcx> = Const<TyCtxt<'tcx>>;

Aliased Type§

pub struct Const<'tcx>(pub Interned<'tcx, WithCachedTypeInfo<ConstKind<TyCtxt<'tcx>>>>);

Tuple Fields§

§0: Interned<'tcx, WithCachedTypeInfo<ConstKind<TyCtxt<'tcx>>>>

Trait Implementations§

Source§

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

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 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 }
Source§

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

Source§

impl Erasable for Const<'_>

Source§

type Storage = [u8; 8]

Storage type to used for erased values of this type. Should be [u8; N], where N is equal to size_of::<Self>. Read more
Source§

impl<'tcx, P: Printer<'tcx>> Print<P> for Const<'tcx>

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 8 bytes