Skip to content

Commit 00e1475

Browse files
authored
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.
2 parents 3c83eab + b8701ff commit 00e1475

File tree

1 file changed

+21
-38
lines changed

1 file changed

+21
-38
lines changed

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+21-38
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,6 @@ enum Scope<'a> {
137137
s: ScopeRef<'a>,
138138
},
139139

140-
/// A scope which either determines unspecified lifetimes or errors
141-
/// on them (e.g., due to ambiguity).
142-
Elision {
143-
s: ScopeRef<'a>,
144-
},
145-
146140
/// Use a specific lifetime (if `Some`) or leave it unset (to be
147141
/// inferred in a function body or potentially error outside one),
148142
/// for the default choice of lifetime in a trait object type.
@@ -211,7 +205,6 @@ impl<'a> fmt::Debug for TruncatedScopeDebug<'a> {
211205
Scope::Body { id, s: _ } => {
212206
f.debug_struct("Body").field("id", id).field("s", &"..").finish()
213207
}
214-
Scope::Elision { s: _ } => f.debug_struct("Elision").field("s", &"..").finish(),
215208
Scope::ObjectLifetimeDefault { lifetime, s: _ } => f
216209
.debug_struct("ObjectLifetimeDefault")
217210
.field("lifetime", lifetime)
@@ -325,9 +318,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
325318
break (vec![], BinderScopeType::Normal);
326319
}
327320

328-
Scope::Elision { s, .. }
329-
| Scope::ObjectLifetimeDefault { s, .. }
330-
| Scope::AnonConstBoundary { s } => {
321+
Scope::ObjectLifetimeDefault { s, .. } | Scope::AnonConstBoundary { s } => {
331322
scope = s;
332323
}
333324

@@ -526,16 +517,12 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
526517
| hir::ItemKind::Macro(..)
527518
| hir::ItemKind::Mod(..)
528519
| hir::ItemKind::ForeignMod { .. }
520+
| hir::ItemKind::Static(..)
521+
| hir::ItemKind::Const(..)
529522
| hir::ItemKind::GlobalAsm(..) => {
530523
// These sorts of items have no lifetime parameters at all.
531524
intravisit::walk_item(self, item);
532525
}
533-
hir::ItemKind::Static(..) | hir::ItemKind::Const(..) => {
534-
// No lifetime parameters, but implied 'static.
535-
self.with(Scope::Elision { s: self.scope }, |this| {
536-
intravisit::walk_item(this, item)
537-
});
538-
}
539526
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
540527
origin: hir::OpaqueTyOrigin::TyAlias { .. },
541528
..
@@ -727,12 +714,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
727714
// Elided lifetimes are not allowed in non-return
728715
// position impl Trait
729716
let scope = Scope::TraitRefBoundary { s: self.scope };
730-
self.with(scope, |this| {
731-
let scope = Scope::Elision { s: this.scope };
732-
this.with(scope, |this| {
733-
intravisit::walk_item(this, opaque_ty);
734-
})
735-
});
717+
self.with(scope, |this| intravisit::walk_item(this, opaque_ty));
736718

737719
return;
738720
}
@@ -1293,8 +1275,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
12931275
scope = s;
12941276
}
12951277

1296-
Scope::Elision { s, .. }
1297-
| Scope::ObjectLifetimeDefault { s, .. }
1278+
Scope::ObjectLifetimeDefault { s, .. }
12981279
| Scope::Supertrait { s, .. }
12991280
| Scope::TraitRefBoundary { s, .. }
13001281
| Scope::AnonConstBoundary { s } => {
@@ -1357,7 +1338,6 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
13571338
Scope::Root { .. } => break,
13581339
Scope::Binder { s, .. }
13591340
| Scope::Body { s, .. }
1360-
| Scope::Elision { s, .. }
13611341
| Scope::ObjectLifetimeDefault { s, .. }
13621342
| Scope::Supertrait { s, .. }
13631343
| Scope::TraitRefBoundary { s, .. }
@@ -1409,8 +1389,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
14091389
scope = s;
14101390
}
14111391

1412-
Scope::Elision { s, .. }
1413-
| Scope::ObjectLifetimeDefault { s, .. }
1392+
Scope::ObjectLifetimeDefault { s, .. }
14141393
| Scope::Supertrait { s, .. }
14151394
| Scope::TraitRefBoundary { s, .. } => {
14161395
scope = s;
@@ -1483,7 +1462,6 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
14831462
Scope::Root { .. } => break,
14841463
Scope::Binder { s, .. }
14851464
| Scope::Body { s, .. }
1486-
| Scope::Elision { s, .. }
14871465
| Scope::ObjectLifetimeDefault { s, .. }
14881466
| Scope::Supertrait { s, .. }
14891467
| Scope::TraitRefBoundary { s, .. }
@@ -1564,7 +1542,6 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
15641542
Scope::Body { .. } => break true,
15651543

15661544
Scope::Binder { s, .. }
1567-
| Scope::Elision { s, .. }
15681545
| Scope::ObjectLifetimeDefault { s, .. }
15691546
| Scope::Supertrait { s, .. }
15701547
| Scope::TraitRefBoundary { s, .. }
@@ -1832,14 +1809,20 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
18321809
output: Option<&'tcx hir::Ty<'tcx>>,
18331810
in_closure: bool,
18341811
) {
1835-
self.with(Scope::Elision { s: self.scope }, |this| {
1836-
for input in inputs {
1837-
this.visit_ty(input);
1838-
}
1839-
if !in_closure && let Some(output) = output {
1840-
this.visit_ty(output);
1841-
}
1842-
});
1812+
self.with(
1813+
Scope::ObjectLifetimeDefault {
1814+
lifetime: Some(ResolvedArg::StaticLifetime),
1815+
s: self.scope,
1816+
},
1817+
|this| {
1818+
for input in inputs {
1819+
this.visit_ty(input);
1820+
}
1821+
if !in_closure && let Some(output) = output {
1822+
this.visit_ty(output);
1823+
}
1824+
},
1825+
);
18431826
if in_closure && let Some(output) = output {
18441827
self.visit_ty(output);
18451828
}
@@ -1859,7 +1842,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
18591842
scope = s;
18601843
}
18611844

1862-
Scope::Root { .. } | Scope::Elision { .. } => break ResolvedArg::StaticLifetime,
1845+
Scope::Root { .. } => break ResolvedArg::StaticLifetime,
18631846

18641847
Scope::Body { .. } | Scope::ObjectLifetimeDefault { lifetime: None, .. } => return,
18651848

0 commit comments

Comments
 (0)