#[repr(C)]pub struct ConstArg<'hir, Unambig = ()> {
pub hir_id: HirId,
pub kind: ConstArgKind<'hir, Unambig>,
}
Expand description
A constant that enters the type system, used for arguments to const generics (e.g. array lengths).
These are distinct from AnonConst
as anon consts in the type system are not allowed
to use any generic parameters, therefore we must represent N
differently. Additionally
future designs for supporting generic parameters in const arguments will likely not use
an anon const based design.
So, ConstArg
(specifically, ConstArgKind
) distinguishes between const args
that are just paths (currently just bare const params)
versus const args that are literals or have arbitrary computations (e.g., { 1 + 3 }
).
The Unambig
generic parameter represents whether the position this const is from is
unambiguously a const or ambiguous as to whether it is a type or a const. When in an
ambiguous context the parameter is instantiated with an uninhabited type making the
ConstArgKind::Infer
variant unusable and GenericArg::Infer
is used instead.
Fields§
§hir_id: HirId
§kind: ConstArgKind<'hir, Unambig>
Implementations§
Source§impl<'hir> ConstArg<'hir, AmbigArg>
impl<'hir> ConstArg<'hir, AmbigArg>
Sourcepub fn as_unambig_ct(&self) -> &ConstArg<'hir>
pub fn as_unambig_ct(&self) -> &ConstArg<'hir>
Converts a ConstArg
in an ambiguous position to one in an unambiguous position.
Functions accepting an unambiguous consts may expect the ConstArgKind::Infer
variant
to be used. Care should be taken to separately handle infer consts when calling this
function as it cannot be handled by downstream code making use of the returned const.
In practice this may mean overriding the Visitor::visit_infer
method on hir visitors, or
specifically matching on GenericArg::Infer
when handling generic arguments.
Source§impl<'hir> ConstArg<'hir>
impl<'hir> ConstArg<'hir>
Sourcepub fn try_as_ambig_ct(&self) -> Option<&ConstArg<'hir, AmbigArg>>
pub fn try_as_ambig_ct(&self) -> Option<&ConstArg<'hir, AmbigArg>>
Converts a ConstArg
in an unambigous position to one in an ambiguous position. This is
fallible as the ConstArgKind::Infer
variant is not present in ambiguous positions.
Functions accepting ambiguous consts will not handle the ConstArgKind::Infer
variant, if
infer consts are relevant to you then care should be taken to handle them separately.
Trait Implementations§
Source§impl<'hir, Unambig, __CTX> HashStable<__CTX> for ConstArg<'hir, Unambig>where
__CTX: HashStableContext,
Unambig: HashStable<__CTX>,
impl<'hir, Unambig, __CTX> HashStable<__CTX> for ConstArg<'hir, Unambig>where
__CTX: HashStableContext,
Unambig: HashStable<__CTX>,
fn hash_stable(&self, __hcx: &mut __CTX, __hasher: &mut StableHasher)
impl<'hir, Unambig: Copy> Copy for ConstArg<'hir, Unambig>
Auto Trait Implementations§
impl<'hir, Unambig> DynSend for ConstArg<'hir, Unambig>where
Unambig: DynSend,
impl<'hir, Unambig> DynSync for ConstArg<'hir, Unambig>where
Unambig: DynSync,
impl<'hir, Unambig> Freeze for ConstArg<'hir, Unambig>where
Unambig: Freeze,
impl<'hir, Unambig> RefUnwindSafe for ConstArg<'hir, Unambig>where
Unambig: RefUnwindSafe,
impl<'hir, Unambig> Send for ConstArg<'hir, Unambig>where
Unambig: Send,
impl<'hir, Unambig> Sync for ConstArg<'hir, Unambig>where
Unambig: Sync,
impl<'hir, Unambig> Unpin for ConstArg<'hir, Unambig>where
Unambig: Unpin,
impl<'hir, Unambig> UnwindSafe for ConstArg<'hir, Unambig>where
Unambig: UnwindSafe,
Blanket Implementations§
Source§impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere
T: Copy,
impl<'tcx, T> ArenaAllocatable<'tcx, IsCopy> for Twhere
T: Copy,
fn allocate_on(self, arena: &'tcx Arena<'tcx>) -> &'tcx mut T
fn allocate_from_iter( arena: &'tcx Arena<'tcx>, iter: impl IntoIterator<Item = T>, ) -> &'tcx mut [T]
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.