Enum rustc_ast_lowering::AnonymousLifetimeMode[][src]

pub(crate) enum AnonymousLifetimeMode {
    CreateParameter,
    ReportError,
    PassThrough,
}
Expand description

What to do when we encounter an anonymous lifetime reference. Anonymous lifetime references come in two flavors. You have implicit, or fully elided, references to lifetimes, like the one in &T or Ref<T>, and you have '_ lifetimes, like &'_ T or Ref<'_, T>. These often behave the same, but not always:

  • certain usages of implicit references are deprecated, like Ref<T>, and we sometimes just give hard errors in those cases as well.
  • for object bounds there is a difference: Box<dyn Foo> is not the same as Box<dyn Foo + '_>.

We describe the effects of the various modes in terms of three cases:

  • Modern – includes all uses of '_, but also the lifetime arg of a & (e.g., the missing lifetime in something like &T)
  • Dyn Bound – if you have something like Box<dyn Foo>, there is an elided lifetime bound (Box<dyn Foo + 'X>). These elided bounds follow special rules. Note that this only covers cases where nothing is written; the '_ in Box<dyn Foo + '_> is a case of “modern” elision.
  • Deprecated – this covers cases like Ref<T>, where the lifetime parameter to ref is completely elided. Ref<'_, T> would be the modern, non-deprecated equivalent.

Currently, the handling of lifetime elision is somewhat spread out between HIR lowering and – as described below – the resolve_lifetime module. Often we “fallthrough” to that code by generating an “elided” or “underscore” lifetime name. In the future, we probably want to move everything into HIR lowering.

Variants

CreateParameter

For Modern cases, create a new anonymous region parameter and reference that.

For Dyn Bound cases, pass responsibility to resolve_lifetime code.

For Deprecated cases, report an error.

ReportError

Give a hard error when either & or '_ is written. Used to rule out things like where T: Foo<'_>. Does not imply an error on default object bounds (e.g., Box<dyn Foo>).

PassThrough

Pass responsibility to resolve_lifetime code for all cases.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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 resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

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: 1 byte

Size for each variant:

  • CreateParameter: 0 bytes
  • ReportError: 0 bytes
  • PassThrough: 0 bytes