Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@alexreg
Created February 25, 2019 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexreg/1bd1774426be6bb3ddc8b595deb60f70 to your computer and use it in GitHub Desktop.
Save alexreg/1bd1774426be6bb3ddc8b595deb60f70 to your computer and use it in GitHub Desktop.
/// 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 => {}
}
self.new_implicit_lifetime(span)
}
fn new_implicit_lifetime(&mut self, span: Span) -> hir::Lifetime {
let LoweredNodeId { node_id, hir_id } = self.next_id();
hir::Lifetime {
id: node_id,
hir_id,
span,
name: hir::LifetimeName::Implicit,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment