Skip to content

Instantly share code, notes, and snippets.

@alexreg alexreg/a
Created Feb 25, 2019

What would you like to do?
/// Invoked to create the lifetime argument(s) for an elided trait object
/// bound, like the bound in `Box<dyn Debug>`. This method is not invoked
/// when the bound is written, even if it is written with `'_` like in
/// `Box<dyn Debug + '_>`. In those cases, `lower_lifetime` is invoked.
fn elided_dyn_bound(&mut self, span: Span) -> hir::Lifetime {
match self.anonymous_lifetime_mode {
// NB. We intentionally ignore the create-parameter mode here.
// and instead "pass through" to resolve-lifetimes, which will apply
// the object-lifetime-defaulting rules. Elided object lifetime defaults
// do not act like other elided lifetimes. In other words, given this:
// impl Foo for Box<dyn Debug>
// we do not introduce a fresh `'_` to serve as the bound, but instead
// ultimately translate to the equivalent of:
// impl Foo for Box<dyn Debug + 'static>
// `resolve_lifetime` has the code to make that happen.
AnonymousLifetimeMode::CreateParameter => {}
AnonymousLifetimeMode::ReportError => {
// ReportError applies to explicit use of `'_`.
// This is the normal case.
AnonymousLifetimeMode::PassThrough => {}
fn new_implicit_lifetime(&mut self, span: Span) -> hir::Lifetime {
let LoweredNodeId { node_id, hir_id } = self.next_id();
hir::Lifetime {
id: node_id,
name: hir::LifetimeName::Implicit,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.