Rollup merge of #113950 - cjgillot:clean-resolve, r=jackh726
Remove Scope::Elision from bound-vars resolution. This scope is a remnant of HIR-based lifetime resolution. It's only role was to ensure that object lifetime resolution falled back to `'static`. This can be done using `ObjectLifetimeDefault` scope.
This commit is contained in:
commit
00e147543c
@ -137,12 +137,6 @@ enum Scope<'a> {
|
||||
s: ScopeRef<'a>,
|
||||
},
|
||||
|
||||
/// A scope which either determines unspecified lifetimes or errors
|
||||
/// on them (e.g., due to ambiguity).
|
||||
Elision {
|
||||
s: ScopeRef<'a>,
|
||||
},
|
||||
|
||||
/// Use a specific lifetime (if `Some`) or leave it unset (to be
|
||||
/// inferred in a function body or potentially error outside one),
|
||||
/// for the default choice of lifetime in a trait object type.
|
||||
@ -211,7 +205,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
Scope::Body { id, s: _ } => {
|
||||
f.debug_struct("Body").field("id", id).field("s", &"..").finish()
|
||||
}
|
||||
Scope::Elision { s: _ } => f.debug_struct("Elision").field("s", &"..").finish(),
|
||||
Scope::ObjectLifetimeDefault { lifetime, s: _ } => f
|
||||
.debug_struct("ObjectLifetimeDefault")
|
||||
.field("lifetime", lifetime)
|
||||
@ -325,9 +318,7 @@ fn poly_trait_ref_binder_info(&mut self) -> (Vec<ty::BoundVariableKind>, BinderS
|
||||
break (vec![], BinderScopeType::Normal);
|
||||
}
|
||||
|
||||
Scope::Elision { s, .. }
|
||||
| Scope::ObjectLifetimeDefault { s, .. }
|
||||
| Scope::AnonConstBoundary { s } => {
|
||||
Scope::ObjectLifetimeDefault { s, .. } | Scope::AnonConstBoundary { s } => {
|
||||
scope = s;
|
||||
}
|
||||
|
||||
@ -526,16 +517,12 @@ fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
|
||||
| hir::ItemKind::Macro(..)
|
||||
| hir::ItemKind::Mod(..)
|
||||
| hir::ItemKind::ForeignMod { .. }
|
||||
| hir::ItemKind::Static(..)
|
||||
| hir::ItemKind::Const(..)
|
||||
| hir::ItemKind::GlobalAsm(..) => {
|
||||
// These sorts of items have no lifetime parameters at all.
|
||||
intravisit::walk_item(self, item);
|
||||
}
|
||||
hir::ItemKind::Static(..) | hir::ItemKind::Const(..) => {
|
||||
// No lifetime parameters, but implied 'static.
|
||||
self.with(Scope::Elision { s: self.scope }, |this| {
|
||||
intravisit::walk_item(this, item)
|
||||
});
|
||||
}
|
||||
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
|
||||
origin: hir::OpaqueTyOrigin::TyAlias { .. },
|
||||
..
|
||||
@ -727,12 +714,7 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
|
||||
// Elided lifetimes are not allowed in non-return
|
||||
// position impl Trait
|
||||
let scope = Scope::TraitRefBoundary { s: self.scope };
|
||||
self.with(scope, |this| {
|
||||
let scope = Scope::Elision { s: this.scope };
|
||||
this.with(scope, |this| {
|
||||
intravisit::walk_item(this, opaque_ty);
|
||||
})
|
||||
});
|
||||
self.with(scope, |this| intravisit::walk_item(this, opaque_ty));
|
||||
|
||||
return;
|
||||
}
|
||||
@ -1293,8 +1275,7 @@ fn resolve_lifetime_ref(
|
||||
scope = s;
|
||||
}
|
||||
|
||||
Scope::Elision { s, .. }
|
||||
| Scope::ObjectLifetimeDefault { s, .. }
|
||||
Scope::ObjectLifetimeDefault { s, .. }
|
||||
| Scope::Supertrait { s, .. }
|
||||
| Scope::TraitRefBoundary { s, .. }
|
||||
| Scope::AnonConstBoundary { s } => {
|
||||
@ -1357,7 +1338,6 @@ fn resolve_lifetime_ref(
|
||||
Scope::Root { .. } => break,
|
||||
Scope::Binder { s, .. }
|
||||
| Scope::Body { s, .. }
|
||||
| Scope::Elision { s, .. }
|
||||
| Scope::ObjectLifetimeDefault { s, .. }
|
||||
| Scope::Supertrait { s, .. }
|
||||
| Scope::TraitRefBoundary { s, .. }
|
||||
@ -1409,8 +1389,7 @@ fn resolve_type_ref(&mut self, param_def_id: LocalDefId, hir_id: hir::HirId) {
|
||||
scope = s;
|
||||
}
|
||||
|
||||
Scope::Elision { s, .. }
|
||||
| Scope::ObjectLifetimeDefault { s, .. }
|
||||
Scope::ObjectLifetimeDefault { s, .. }
|
||||
| Scope::Supertrait { s, .. }
|
||||
| Scope::TraitRefBoundary { s, .. } => {
|
||||
scope = s;
|
||||
@ -1483,7 +1462,6 @@ fn resolve_type_ref(&mut self, param_def_id: LocalDefId, hir_id: hir::HirId) {
|
||||
Scope::Root { .. } => break,
|
||||
Scope::Binder { s, .. }
|
||||
| Scope::Body { s, .. }
|
||||
| Scope::Elision { s, .. }
|
||||
| Scope::ObjectLifetimeDefault { s, .. }
|
||||
| Scope::Supertrait { s, .. }
|
||||
| Scope::TraitRefBoundary { s, .. }
|
||||
@ -1564,7 +1542,6 @@ fn visit_segment_args(
|
||||
Scope::Body { .. } => break true,
|
||||
|
||||
Scope::Binder { s, .. }
|
||||
| Scope::Elision { s, .. }
|
||||
| Scope::ObjectLifetimeDefault { s, .. }
|
||||
| Scope::Supertrait { s, .. }
|
||||
| Scope::TraitRefBoundary { s, .. }
|
||||
@ -1832,14 +1809,20 @@ fn visit_fn_like_elision(
|
||||
output: Option<&'tcx hir::Ty<'tcx>>,
|
||||
in_closure: bool,
|
||||
) {
|
||||
self.with(Scope::Elision { s: self.scope }, |this| {
|
||||
for input in inputs {
|
||||
this.visit_ty(input);
|
||||
}
|
||||
if !in_closure && let Some(output) = output {
|
||||
this.visit_ty(output);
|
||||
}
|
||||
});
|
||||
self.with(
|
||||
Scope::ObjectLifetimeDefault {
|
||||
lifetime: Some(ResolvedArg::StaticLifetime),
|
||||
s: self.scope,
|
||||
},
|
||||
|this| {
|
||||
for input in inputs {
|
||||
this.visit_ty(input);
|
||||
}
|
||||
if !in_closure && let Some(output) = output {
|
||||
this.visit_ty(output);
|
||||
}
|
||||
},
|
||||
);
|
||||
if in_closure && let Some(output) = output {
|
||||
self.visit_ty(output);
|
||||
}
|
||||
@ -1859,7 +1842,7 @@ fn resolve_object_lifetime_default(&mut self, lifetime_ref: &'tcx hir::Lifetime)
|
||||
scope = s;
|
||||
}
|
||||
|
||||
Scope::Root { .. } | Scope::Elision { .. } => break ResolvedArg::StaticLifetime,
|
||||
Scope::Root { .. } => break ResolvedArg::StaticLifetime,
|
||||
|
||||
Scope::Body { .. } | Scope::ObjectLifetimeDefault { lifetime: None, .. } => return,
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user