/// User-given names or fresh (synthetic) names.
Param(LocalDefId, ParamName),
- /// User wrote nothing (e.g., the lifetime in `&u32`).
- Implicit,
-
/// Implicit lifetime in a context like `dyn Foo`. This is
/// distinguished from implicit lifetimes elsewhere because the
/// lifetime that they default to must appear elsewhere within the
/// that was already reported.
Error,
- /// User wrote specifies `'_`.
+ /// User wrote an anonymous lifetime, either `'_` or nothing.
Underscore,
/// User wrote `'static`.
impl LifetimeName {
pub fn ident(&self) -> Ident {
match *self {
- LifetimeName::ImplicitObjectLifetimeDefault
- | LifetimeName::Implicit
- | LifetimeName::Error => Ident::empty(),
+ LifetimeName::ImplicitObjectLifetimeDefault | LifetimeName::Error => Ident::empty(),
LifetimeName::Underscore => Ident::with_dummy_span(kw::UnderscoreLifetime),
LifetimeName::Static => Ident::with_dummy_span(kw::StaticLifetime),
LifetimeName::Param(_, param_name) => param_name.ident(),
pub fn is_anonymous(&self) -> bool {
match *self {
LifetimeName::ImplicitObjectLifetimeDefault
- | LifetimeName::Implicit
| LifetimeName::Underscore
| LifetimeName::Param(_, ParamName::Fresh)
| LifetimeName::Error => true,
pub fn is_elided(&self) -> bool {
match self {
- LifetimeName::ImplicitObjectLifetimeDefault
- | LifetimeName::Implicit
- | LifetimeName::Underscore => true,
+ LifetimeName::ImplicitObjectLifetimeDefault | LifetimeName::Underscore => true,
// It might seem surprising that `Fresh` counts as
// *not* elided -- but this is because, as far as the code
/// error on default object bounds (e.g., `Box<dyn Foo>`).
AnonymousReportError,
- /// Pass responsibility to `resolve_lifetime` code for all cases.
- AnonymousPassThrough(NodeId),
-
/// Replace all anonymous lifetimes by provided lifetime.
Elided(LifetimeRes),
let previous_state = replace(&mut this.in_func_body, true);
// Resolve the function body, potentially inside the body of an async closure
this.with_lifetime_rib(
- LifetimeRibKind::AnonymousPassThrough(fn_id),
+ LifetimeRibKind::Elided(LifetimeRes::Anonymous { binder: fn_id }),
|this| this.visit_block(body),
);
this.with_lifetime_rib(
match binder {
ClosureBinder::NotPresent => {
- LifetimeRibKind::AnonymousPassThrough(fn_id)
+ LifetimeRibKind::Elided(LifetimeRes::Anonymous {
+ binder: fn_id,
+ })
}
ClosureBinder::For { .. } => LifetimeRibKind::AnonymousReportError,
},
let previous_state = replace(&mut this.in_func_body, true);
// Resolve the function body, potentially inside the body of an async closure
this.with_lifetime_rib(
- LifetimeRibKind::AnonymousPassThrough(fn_id),
+ LifetimeRibKind::Elided(LifetimeRes::Anonymous { binder: fn_id }),
|this| this.visit_expr(body),
);
visit::walk_generic_args(self, path_span, args);
break;
}
- LifetimeRibKind::AnonymousPassThrough(..)
- | LifetimeRibKind::AnonymousCreateParameter { .. }
+ LifetimeRibKind::AnonymousCreateParameter { .. }
| LifetimeRibKind::AnonymousReportError
| LifetimeRibKind::Elided(_)
| LifetimeRibKind::ElisionFailure
| LifetimeRibKind::AnonymousReportError
| LifetimeRibKind::ElisionFailure => Some(LifetimeUseSet::Many),
// An anonymous lifetime is legal here, go ahead.
- LifetimeRibKind::AnonymousPassThrough(_)
- | LifetimeRibKind::AnonymousCreateParameter { .. } => {
+ LifetimeRibKind::AnonymousCreateParameter { .. } => {
Some(LifetimeUseSet::One { use_span: ident.span, use_ctxt })
}
// Only report if eliding the lifetime would have the same
self.record_lifetime_res(lifetime.id, LifetimeRes::Error, elision_candidate);
return;
}
- LifetimeRibKind::AnonymousPassThrough(node_id) => {
- self.record_lifetime_res(
- lifetime.id,
- LifetimeRes::Anonymous { binder: node_id, elided },
- elision_candidate,
- );
- return;
- }
LifetimeRibKind::Elided(res) => {
self.record_lifetime_res(lifetime.id, res, elision_candidate);
return;
// Do not create a parameter for patterns and expressions.
for rib in self.lifetime_ribs.iter().rev() {
match rib.kind {
- LifetimeRibKind::AnonymousPassThrough(binder) => {
- let res = LifetimeRes::Anonymous { binder, elided: true };
+ LifetimeRibKind::Elided(res @ LifetimeRes::Anonymous { .. }) => {
for id in node_ids {
self.record_lifetime_res(id, res, LifetimeElisionCandidate::Named);
}
// FIXME(cjgillot) This resolution is wrong, but this does not matter
// since these cases are erroneous anyway. Lifetime resolution should
// emit a "missing lifetime specifier" diagnostic.
- let res =
- LifetimeRes::Anonymous { binder: DUMMY_NODE_ID, elided: true };
+ let res = LifetimeRes::Anonymous { binder: DUMMY_NODE_ID };
for id in node_ids {
self.record_lifetime_res(id, res, LifetimeElisionCandidate::Named);
}
}
break;
}
- // `PassThrough` is the normal case.
- LifetimeRibKind::AnonymousPassThrough(binder) => {
- let res = LifetimeRes::Anonymous { binder, elided: true };
- let mut candidate = LifetimeElisionCandidate::Missing(missing_lifetime);
- for id in node_ids {
- self.record_lifetime_res(
- id,
- res,
- replace(&mut candidate, LifetimeElisionCandidate::Ignore),
- );
- }
- break;
- }
LifetimeRibKind::Elided(res) => {
let mut candidate = LifetimeElisionCandidate::Missing(missing_lifetime);
for id in node_ids {
this.visit_ty(ty);
});
this.with_lifetime_rib(
- LifetimeRibKind::AnonymousPassThrough(item.id),
+ LifetimeRibKind::Elided(LifetimeRes::Anonymous { binder: item.id }),
|this| {
if let Some(expr) = expr {
let constant_item_kind = match item.kind {
// Type parameters can already be used and as associated consts are
// not used as part of the type system, this is far less surprising.
self.with_lifetime_rib(
- LifetimeRibKind::AnonymousPassThrough(item.id),
+ LifetimeRibKind::Elided(LifetimeRes::Anonymous { binder: item.id }),
|this| {
this.with_constant_rib(
IsRepeatExpr::No,
// Type parameters can already be used and as associated consts are
// not used as part of the type system, this is far less surprising.
self.with_lifetime_rib(
- LifetimeRibKind::AnonymousPassThrough(item.id),
+ LifetimeRibKind::Elided(LifetimeRes::Anonymous { binder: item.id }),
|this| {
this.with_constant_rib(
IsRepeatExpr::No,
// `Box<dyn Debug + 'static>`.
self.resolve_object_lifetime_default(lifetime)
}
- LifetimeName::Implicit | LifetimeName::Underscore => {
+ LifetimeName::Underscore => {
// If the user writes `'_`, we use the *ordinary* elision
// rules. So the `'_` in e.g., `Box<dyn Debug + '_>` will be
// resolved the same as the `'_` in `&'_ Foo`.
#[tracing::instrument(level = "debug", skip(self))]
fn visit_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime) {
match lifetime_ref.name {
- hir::LifetimeName::ImplicitObjectLifetimeDefault
- | hir::LifetimeName::Implicit
- | hir::LifetimeName::Underscore => self.resolve_elided_lifetimes(&[lifetime_ref]),
+ hir::LifetimeName::ImplicitObjectLifetimeDefault | hir::LifetimeName::Underscore => {
+ self.resolve_elided_lifetimes(&[lifetime_ref])
+ }
hir::LifetimeName::Static => self.insert_lifetime(lifetime_ref, Region::Static),
hir::LifetimeName::Param(param_def_id, _) => {
self.resolve_lifetime_ref(param_def_id, lifetime_ref)