Enum rustc_ast_lowering::ImplTraitContext [−][src]
pub(crate) enum ImplTraitContext<'b, 'a> {
Universal(&'b mut Vec<GenericParam<'a>>, LocalDefId),
ReturnPositionOpaqueTy {
fn_def_id: DefId,
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
.
Tuple Fields of Universal
0: &'b mut Vec<GenericParam<'a>>
1: LocalDefId
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
.
Fields of ReturnPositionOpaqueTy
fn_def_id: DefId
DefId
for the parent function, used to look up necessary
information later.
origin: OpaqueTyOrigin
Origin: Either OpaqueTyOrigin::FnReturn or OpaqueTyOrigin::AsyncFn,
Impl trait in type aliases.
Fields of TypeAliasesOpaqueTy
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
.
Disallowed(ImplTraitPosition)
impl Trait
is not accepted in this position.
Tuple Fields of Disallowed
Implementations
Trait Implementations
Auto Trait Implementations
impl<'b, 'a> RefUnwindSafe for ImplTraitContext<'b, 'a>
impl<'b, 'a> !Send for ImplTraitContext<'b, 'a>
impl<'b, 'a> !Sync for ImplTraitContext<'b, 'a>
impl<'b, 'a> Unpin for ImplTraitContext<'b, 'a> where
'a: 'b,
impl<'b, 'a> !UnwindSafe for ImplTraitContext<'b, 'a>
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
: 11 bytesTypeAliasesOpaqueTy
: 15 bytesDisallowed
: 1 byte