Skip to content

Commit 556b027

Browse files
committed
Stop creating anonymous late lifetimes.
1 parent ad1b181 commit 556b027

File tree

5 files changed

+4
-85
lines changed

5 files changed

+4
-85
lines changed

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs

+1-30
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,6 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
100100
// the lifetime of the TyRptr
101101
let hir_id = lifetime.hir_id;
102102
match (self.tcx.named_region(hir_id), self.bound_region) {
103-
// Find the index of the anonymous region that was part of the
104-
// error. We will then search the function parameters for a bound
105-
// region at the right depth with the same index
106-
(
107-
Some(rl::Region::LateBoundAnon(debruijn_index, _, anon_index)),
108-
ty::BrAnon(br_index),
109-
) => {
110-
debug!(
111-
"LateBoundAnon depth = {:?} anon_index = {:?} br_index={:?}",
112-
debruijn_index, anon_index, br_index
113-
);
114-
if debruijn_index == self.current_index && anon_index == br_index {
115-
self.found_type = Some(arg);
116-
return; // we can stop visiting now
117-
}
118-
}
119-
120103
// Find the index of the named region that was part of the
121104
// error. We will then search the function parameters for a bound
122105
// region at the right depth with the same index
@@ -151,8 +134,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
151134
rl::Region::Static
152135
| rl::Region::Free(_, _)
153136
| rl::Region::EarlyBound(_, _)
154-
| rl::Region::LateBound(_, _, _)
155-
| rl::Region::LateBoundAnon(_, _, _),
137+
| rl::Region::LateBound(_, _, _),
156138
)
157139
| None,
158140
_,
@@ -206,16 +188,6 @@ impl<'tcx> Visitor<'tcx> for TyPathVisitor<'tcx> {
206188
fn visit_lifetime(&mut self, lifetime: &hir::Lifetime) {
207189
match (self.tcx.named_region(lifetime.hir_id), self.bound_region) {
208190
// the lifetime of the TyPath!
209-
(
210-
Some(rl::Region::LateBoundAnon(debruijn_index, _, anon_index)),
211-
ty::BrAnon(br_index),
212-
) => {
213-
if debruijn_index == self.current_index && anon_index == br_index {
214-
self.found_it = true;
215-
return;
216-
}
217-
}
218-
219191
(Some(rl::Region::EarlyBound(_, id)), ty::BrNamed(def_id, _)) => {
220192
debug!("EarlyBound id={:?} def_id={:?}", id, def_id);
221193
if id == def_id {
@@ -239,7 +211,6 @@ impl<'tcx> Visitor<'tcx> for TyPathVisitor<'tcx> {
239211
rl::Region::Static
240212
| rl::Region::EarlyBound(_, _)
241213
| rl::Region::LateBound(_, _, _)
242-
| rl::Region::LateBoundAnon(_, _, _)
243214
| rl::Region::Free(_, _),
244215
)
245216
| None,

compiler/rustc_middle/src/middle/resolve_lifetime.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub enum Region {
1212
Static,
1313
EarlyBound(/* index */ u32, /* lifetime decl */ DefId),
1414
LateBound(ty::DebruijnIndex, /* late-bound index */ u32, /* lifetime decl */ DefId),
15-
LateBoundAnon(ty::DebruijnIndex, /* late-bound index */ u32, /* anon index */ u32),
1615
Free(DefId, /* lifetime decl */ DefId),
1716
}
1817

compiler/rustc_resolve/src/late/lifetimes.rs

+1-36
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use rustc_span::def_id::DefId;
2424
use rustc_span::symbol::{sym, Ident};
2525
use rustc_span::Span;
2626
use std::borrow::Cow;
27-
use std::cell::Cell;
2827
use std::fmt;
2928
use std::mem::take;
3029

@@ -33,8 +32,6 @@ trait RegionExt {
3332

3433
fn late(index: u32, hir_map: Map<'_>, param: &GenericParam<'_>) -> (LocalDefId, Region);
3534

36-
fn late_anon(named_late_bound_vars: u32, index: &Cell<u32>) -> Region;
37-
3835
fn id(&self) -> Option<DefId>;
3936

4037
fn shifted(self, amount: u32) -> Region;
@@ -65,16 +62,9 @@ impl RegionExt for Region {
6562
(def_id, Region::LateBound(depth, idx, def_id.to_def_id()))
6663
}
6764

68-
fn late_anon(named_late_bound_vars: u32, index: &Cell<u32>) -> Region {
69-
let i = index.get();
70-
index.set(i + 1);
71-
let depth = ty::INNERMOST;
72-
Region::LateBoundAnon(depth, named_late_bound_vars + i, i)
73-
}
74-
7565
fn id(&self) -> Option<DefId> {
7666
match *self {
77-
Region::Static | Region::LateBoundAnon(..) => None,
67+
Region::Static => None,
7868

7969
Region::EarlyBound(_, id) | Region::LateBound(_, _, id) | Region::Free(_, id) => {
8070
Some(id)
@@ -87,9 +77,6 @@ impl RegionExt for Region {
8777
Region::LateBound(debruijn, idx, id) => {
8878
Region::LateBound(debruijn.shifted_in(amount), idx, id)
8979
}
90-
Region::LateBoundAnon(debruijn, index, anon_index) => {
91-
Region::LateBoundAnon(debruijn.shifted_in(amount), index, anon_index)
92-
}
9380
_ => self,
9481
}
9582
}
@@ -99,9 +86,6 @@ impl RegionExt for Region {
9986
Region::LateBound(debruijn, index, id) => {
10087
Region::LateBound(debruijn.shifted_out_to_binder(binder), index, id)
10188
}
102-
Region::LateBoundAnon(debruijn, index, anon_index) => {
103-
Region::LateBoundAnon(debruijn.shifted_out_to_binder(binder), index, anon_index)
104-
}
10589
_ => self,
10690
}
10791
}
@@ -193,10 +177,6 @@ enum Scope<'a> {
193177

194178
s: ScopeRef<'a>,
195179

196-
/// In some cases not allowing late bounds allows us to avoid ICEs.
197-
/// This is almost ways set to true.
198-
allow_late_bound: bool,
199-
200180
/// If this binder comes from a where clause, specify how it was created.
201181
/// This is used to diagnose inaccessible lifetimes in APIT:
202182
/// ```ignore (illustrative)
@@ -272,7 +252,6 @@ impl<'a> fmt::Debug for TruncatedScopeDebug<'a> {
272252
opaque_type_parent,
273253
scope_type,
274254
hir_id,
275-
allow_late_bound,
276255
where_bound_origin,
277256
s: _,
278257
} => f
@@ -282,7 +261,6 @@ impl<'a> fmt::Debug for TruncatedScopeDebug<'a> {
282261
.field("opaque_type_parent", opaque_type_parent)
283262
.field("scope_type", scope_type)
284263
.field("hir_id", hir_id)
285-
.field("allow_late_bound", allow_late_bound)
286264
.field("where_bound_origin", where_bound_origin)
287265
.field("s", &"..")
288266
.finish(),
@@ -468,9 +446,6 @@ fn late_region_as_bound_region<'tcx>(tcx: TyCtxt<'tcx>, region: &Region) -> ty::
468446
let name = tcx.hir().name(tcx.hir().local_def_id_to_hir_id(def_id.expect_local()));
469447
ty::BoundVariableKind::Region(ty::BrNamed(*def_id, name))
470448
}
471-
Region::LateBoundAnon(_, _, anon_idx) => {
472-
ty::BoundVariableKind::Region(ty::BrAnon(*anon_idx))
473-
}
474449
_ => bug!("{:?} is not a late region", region),
475450
}
476451
}
@@ -605,7 +580,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
605580
next_early_index,
606581
opaque_type_parent: false,
607582
scope_type: BinderScopeType::Normal,
608-
allow_late_bound: true,
609583
where_bound_origin: None,
610584
};
611585

@@ -724,7 +698,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
724698
opaque_type_parent: true,
725699
scope_type: BinderScopeType::Normal,
726700
s: ROOT_SCOPE,
727-
allow_late_bound: false,
728701
where_bound_origin: None,
729702
};
730703
self.with(scope, |this| {
@@ -777,7 +750,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
777750
next_early_index,
778751
opaque_type_parent: false,
779752
scope_type: BinderScopeType::Normal,
780-
allow_late_bound: true,
781753
where_bound_origin: None,
782754
};
783755
self.with(scope, |this| {
@@ -942,7 +914,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
942914
s: self.scope,
943915
opaque_type_parent: false,
944916
scope_type: BinderScopeType::Normal,
945-
allow_late_bound: false,
946917
where_bound_origin: None,
947918
};
948919
self.with(scope, |this| {
@@ -997,7 +968,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
997968
s: self.scope,
998969
opaque_type_parent: true,
999970
scope_type: BinderScopeType::Normal,
1000-
allow_late_bound: false,
1001971
where_bound_origin: None,
1002972
};
1003973
self.with(scope, |this| {
@@ -1059,7 +1029,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
10591029
s: self.scope,
10601030
opaque_type_parent: true,
10611031
scope_type: BinderScopeType::Normal,
1062-
allow_late_bound: true,
10631032
where_bound_origin: None,
10641033
};
10651034
self.with(scope, |this| {
@@ -1173,7 +1142,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
11731142
next_early_index,
11741143
opaque_type_parent: false,
11751144
scope_type: BinderScopeType::Normal,
1176-
allow_late_bound: true,
11771145
where_bound_origin: Some(origin),
11781146
};
11791147
this.with(scope, |this| {
@@ -1246,7 +1214,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
12461214
next_early_index: self.next_early_index(),
12471215
opaque_type_parent: false,
12481216
scope_type,
1249-
allow_late_bound: true,
12501217
where_bound_origin: None,
12511218
};
12521219
self.with(scope, |this| {
@@ -1297,7 +1264,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
12971264
next_early_index,
12981265
opaque_type_parent: false,
12991266
scope_type,
1300-
allow_late_bound: true,
13011267
where_bound_origin: None,
13021268
};
13031269
self.with(scope, |this| {
@@ -1551,7 +1517,6 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15511517
s: self.scope,
15521518
opaque_type_parent: true,
15531519
scope_type: BinderScopeType::Normal,
1554-
allow_late_bound: true,
15551520
where_bound_origin: None,
15561521
};
15571522
self.with(scope, walk);

compiler/rustc_typeck/src/astconv/mod.rs

-8
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
221221
tcx.mk_region(ty::ReLateBound(debruijn, br))
222222
}
223223

224-
Some(rl::Region::LateBoundAnon(debruijn, index, anon_index)) => {
225-
let br = ty::BoundRegion {
226-
var: ty::BoundVar::from_u32(index),
227-
kind: ty::BrAnon(anon_index),
228-
};
229-
tcx.mk_region(ty::ReLateBound(debruijn, br))
230-
}
231-
232224
Some(rl::Region::EarlyBound(index, id)) => {
233225
let name = lifetime_name(id.expect_local());
234226
tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { def_id: id, index, name }))

compiler/rustc_typeck/src/collect.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -1346,16 +1346,8 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S
13461346

13471347
match self.tcx.named_region(lt.hir_id) {
13481348
Some(rl::Region::Static | rl::Region::EarlyBound(..)) => {}
1349-
Some(
1350-
rl::Region::LateBound(debruijn, _, _)
1351-
| rl::Region::LateBoundAnon(debruijn, _, _),
1352-
) if debruijn < self.outer_index => {}
1353-
Some(
1354-
rl::Region::LateBound(..)
1355-
| rl::Region::LateBoundAnon(..)
1356-
| rl::Region::Free(..),
1357-
)
1358-
| None => {
1349+
Some(rl::Region::LateBound(debruijn, _, _)) if debruijn < self.outer_index => {}
1350+
Some(rl::Region::LateBound(..) | rl::Region::Free(..)) | None => {
13591351
self.has_late_bound_regions = Some(lt.span);
13601352
}
13611353
}

0 commit comments

Comments
 (0)