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)

Tuple Fields

0: &'b mut Vec<GenericParam<'a>>

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: DefId

DefId for the parent function, used to look up necessary information later.

origin: OpaqueTyOrigin

Origin: 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)

Tuple Fields

impl Trait is not accepted in this position.

Implementations

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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 bytes
  • ReturnPositionOpaqueTy: 11 bytes
  • TypeAliasesOpaqueTy: 15 bytes
  • Disallowed: 1 byte