pub(crate) enum ImplTraitContext<'b, 'a> {
Universal(&'b mut Vec<GenericParam<'a>>, LocalDefId),
ReturnPositionOpaqueTy {
fn_def_id: LocalDefId,
origin: OpaqueTyOrigin,
},
TypeAliasesOpaqueTy {
capturable_lifetimes: &'b mut FxHashSet<LifetimeName>,
},
Disallowed(ImplTraitPosition),
}Expand description
Context of impl Trait in code, which determines whether it is allowed in an HIR subtree,
and if so, what meaning it has.
Variants
Universal(&'b mut Vec<GenericParam<'a>>, LocalDefId)
Treat impl Trait as shorthand for a new universal generic parameter.
Example: fn foo(x: impl Debug), where impl Debug is conceptually
equivalent to a fresh universal parameter like fn foo<T: Debug>(x: T).
Newly generated parameters should be inserted into the given Vec.
ReturnPositionOpaqueTy
Fields
fn_def_id: LocalDefIdDefId for the parent function, used to look up necessary
information later.
origin: OpaqueTyOriginOrigin: Either OpaqueTyOrigin::FnReturn or OpaqueTyOrigin::AsyncFn,
Treat impl Trait as shorthand for a new opaque type.
Example: fn foo() -> impl Debug, where impl Debug is conceptually
equivalent to a new opaque type like type T = impl Debug; fn foo() -> T.
TypeAliasesOpaqueTy
Fields
capturable_lifetimes: &'b mut FxHashSet<LifetimeName>Set of lifetimes that this opaque type can capture, if it uses them. This includes lifetimes bound since we entered this context. For example:
type A<'b> = impl for<'a> Trait<'a, Out = impl Sized + 'a>;Here the inner opaque type captures 'a because it uses it. It doesn’t
need to capture 'b because it already inherits the lifetime
parameter from A.
Impl trait in type aliases.
Disallowed(ImplTraitPosition)
impl Trait is not accepted in this position.
Implementations
Trait Implementations
Auto Trait Implementations
impl<'b, 'a> RefUnwindSafe for ImplTraitContext
impl<'b, 'a> !Send for ImplTraitContext
impl<'b, 'a> !Sync for ImplTraitContext
impl<'b, 'a> Unpin for ImplTraitContext where
'a: 'b,
impl<'b, 'a> !UnwindSafe for ImplTraitContext
Blanket Implementations
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: 16 bytes
Size for each variant:
Universal: 15 bytesReturnPositionOpaqueTy: 15 bytesTypeAliasesOpaqueTy: 15 bytesDisallowed: 1 byte