Skip to content

Commit e2f7f4a

Browse files
nikomatsakiscsmoe
andcommitted
port nice_region_error code to not track depth but rather index
Co-authored-by: csmoe <[email protected]>
1 parent 8bd4bff commit e2f7f4a

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
7777
tcx: self.tcx,
7878
bound_region: *br,
7979
found_type: None,
80-
depth: 1,
80+
current_index: ty::DebruijnIndex::INNERMOST,
8181
};
8282
nested_visitor.visit_ty(arg);
8383
nested_visitor.found_type
@@ -99,7 +99,7 @@ struct FindNestedTypeVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
9999
// The type where the anonymous lifetime appears
100100
// for e.g. Vec<`&u8`> and <`&u8`>
101101
found_type: Option<&'gcx hir::Ty>,
102-
depth: u32,
102+
current_index: ty::DebruijnIndex,
103103
}
104104

105105
impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
@@ -110,16 +110,16 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
110110
fn visit_ty(&mut self, arg: &'gcx hir::Ty) {
111111
match arg.node {
112112
hir::TyBareFn(_) => {
113-
self.depth += 1;
113+
self.current_index.shift_in(1);
114114
intravisit::walk_ty(self, arg);
115-
self.depth -= 1;
115+
self.current_index.shift_out(1);
116116
return;
117117
}
118118

119119
hir::TyTraitObject(ref bounds, _) => for bound in bounds {
120-
self.depth += 1;
120+
self.current_index.shift_in(1);
121121
self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);
122-
self.depth -= 1;
122+
self.current_index.shift_out(1);
123123
},
124124

125125
hir::TyRptr(ref lifetime, _) => {
@@ -135,11 +135,11 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
135135
) => {
136136
debug!(
137137
"LateBoundAnon depth = {:?} anon_index = {:?} br_index={:?}",
138-
debruijn_index.depth,
138+
debruijn_index,
139139
anon_index,
140140
br_index
141141
);
142-
if debruijn_index.depth == self.depth && anon_index == br_index {
142+
if debruijn_index == self.current_index && anon_index == br_index {
143143
self.found_type = Some(arg);
144144
return; // we can stop visiting now
145145
}
@@ -170,11 +170,11 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
170170
) => {
171171
debug!(
172172
"FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}",
173-
debruijn_index.depth
173+
debruijn_index
174174
);
175175
debug!("self.infcx.tcx.hir.local_def_id(id)={:?}", id);
176176
debug!("def_id={:?}", def_id);
177-
if debruijn_index.depth == self.depth && id == def_id {
177+
if debruijn_index == self.current_index && id == def_id {
178178
self.found_type = Some(arg);
179179
return; // we can stop visiting now
180180
}
@@ -196,7 +196,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
196196
tcx: self.tcx,
197197
found_it: false,
198198
bound_region: self.bound_region,
199-
depth: self.depth,
199+
current_index: self.current_index,
200200
};
201201
intravisit::walk_ty(subvisitor, arg); // call walk_ty; as visit_ty is empty,
202202
// this will visit only outermost type
@@ -222,7 +222,7 @@ struct TyPathVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
222222
tcx: TyCtxt<'a, 'gcx, 'tcx>,
223223
found_it: bool,
224224
bound_region: ty::BoundRegion,
225-
depth: u32,
225+
current_index: ty::DebruijnIndex,
226226
}
227227

228228
impl<'a, 'gcx, 'tcx> Visitor<'gcx> for TyPathVisitor<'a, 'gcx, 'tcx> {
@@ -235,7 +235,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for TyPathVisitor<'a, 'gcx, 'tcx> {
235235
match (self.tcx.named_region(hir_id), self.bound_region) {
236236
// the lifetime of the TyPath!
237237
(Some(rl::Region::LateBoundAnon(debruijn_index, anon_index)), ty::BrAnon(br_index)) => {
238-
if debruijn_index.depth == self.depth && anon_index == br_index {
238+
if debruijn_index == self.current_index && anon_index == br_index {
239239
self.found_it = true;
240240
return;
241241
}
@@ -257,11 +257,11 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for TyPathVisitor<'a, 'gcx, 'tcx> {
257257
(Some(rl::Region::LateBound(debruijn_index, id, _)), ty::BrNamed(def_id, _)) => {
258258
debug!(
259259
"FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}",
260-
debruijn_index.depth
260+
debruijn_index,
261261
);
262262
debug!("id={:?}", id);
263263
debug!("def_id={:?}", def_id);
264-
if debruijn_index.depth == self.depth && id == def_id {
264+
if debruijn_index == self.current_index && id == def_id {
265265
self.found_it = true;
266266
return; // we can stop visiting now
267267
}

0 commit comments

Comments
 (0)