@@ -39,18 +39,19 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
39
39
// }
40
40
// It will later be extended to trait objects.
41
41
pub fn try_report_anon_anon_conflict ( & self , error : & RegionResolutionError < ' tcx > ) -> bool {
42
+ debug ! ( "try_report_anon_anon_conflict" ) ;
42
43
let ( span, sub, sup) = match * error {
43
44
ConcreteFailure ( ref origin, sub, sup) => ( origin. span ( ) , sub, sup) ,
44
45
_ => return false , // inapplicable
45
46
} ;
46
47
47
48
// Determine whether the sub and sup consist of both anonymous (elided) regions.
48
49
let ( ty1, ty2, scope_def_id_1, scope_def_id_2, bregion1, bregion2) = if
49
- self . is_suitable_anonymous_region ( sup, true ) . is_some ( ) &&
50
- self . is_suitable_anonymous_region ( sub, true ) . is_some ( ) {
50
+ self . is_suitable_region ( sup, true ) . is_some ( ) &&
51
+ self . is_suitable_region ( sub, true ) . is_some ( ) {
51
52
if let ( Some ( anon_reg1) , Some ( anon_reg2) ) =
52
- ( self . is_suitable_anonymous_region ( sup, true ) ,
53
- self . is_suitable_anonymous_region ( sub, true ) ) {
53
+ ( self . is_suitable_region ( sup, true ) ,
54
+ self . is_suitable_region ( sub, true ) ) {
54
55
let ( ( def_id1, br1) , ( def_id2, br2) ) = ( anon_reg1, anon_reg2) ;
55
56
let found_arg1 = self . find_anon_type ( sup, & br1) ;
56
57
let found_arg2 = self . find_anon_type ( sub, & br2) ;
@@ -133,6 +134,7 @@ pub struct FindNestedTypeVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
133
134
// The type where the anonymous lifetime appears
134
135
// for e.g. Vec<`&u8`> and <`&u8`>
135
136
pub found_type : Option < & ' gcx hir:: Ty > ,
137
+ //pub depth: u32,
136
138
}
137
139
138
140
impl < ' a , ' gcx , ' tcx > Visitor < ' gcx > for FindNestedTypeVisitor < ' a , ' gcx , ' tcx > {
@@ -144,24 +146,52 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
144
146
// Find the index of the anonymous region that was part of the
145
147
// error. We will then search the function parameters for a bound
146
148
// region at the right depth with the same index.
147
- let br_index = match self . bound_region {
148
- ty:: BrAnon ( index) => index,
149
- _ => return ,
150
- } ;
151
-
152
149
match arg. node {
153
150
hir:: TyRptr ( ref lifetime, _) => {
154
151
match self . infcx . tcx . named_region_map . defs . get ( & lifetime. id ) {
155
152
// the lifetime of the TyRptr
156
- Some ( & rl:: Region :: LateBoundAnon ( debuijn_index, anon_index) ) => {
157
- if debuijn_index. depth == 1 && anon_index == br_index {
153
+ Some ( & rl:: Region :: LateBoundAnon ( debruijn_index, anon_index) ) => {
154
+ let br_index = match self . bound_region {
155
+ ty:: BrAnon ( index) => index,
156
+ _ => return ,
157
+ } ;
158
+ debug ! ( "LateBoundAnon depth = {:?} anon_index = {:?} br_index={:?}" , debruijn_index. depth
159
+ , anon_index, br_index) ;
160
+ if debruijn_index. depth == 1 && anon_index == br_index {
158
161
self . found_type = Some ( arg) ;
159
162
return ; // we can stop visiting now
160
163
}
161
164
}
165
+ Some ( & rl:: Region :: EarlyBound ( _, id) ) => {
166
+ let def_id = match self . bound_region {
167
+ ty:: BrNamed ( def_id, _) => def_id, //def_id of hir::Lifetime
168
+ _ => return ,
169
+ } ;
170
+ debug ! ( "EarlyBound self.infcx.tcx.hir.local_def_id(id) ={:?}
171
+ def_id={:?}" ,
172
+ self . infcx. tcx. hir. local_def_id( id) , def_id) ;
173
+ if self . infcx . tcx . hir . local_def_id ( id) == def_id {
174
+ self . found_type = Some ( arg) ;
175
+ return ; // we can stop visiting now
176
+ }
177
+
178
+ }
179
+
180
+ Some ( & rl:: Region :: LateBound ( debruijn_index, id) ) => {
181
+ let def_id = match self . bound_region {
182
+ ty:: BrNamed ( def_id, _) => def_id, //def_id of hir::Lifetime
183
+ _ => return ,
184
+ } ;
185
+ debug ! ( "LateBound depth = {:?} self.infcx.tcx.hir.local_def_id(id) ={:?}
186
+ def_id={:?}" , debruijn_index. depth
187
+ , self . infcx. tcx. hir. local_def_id( id) , def_id) ;
188
+ if debruijn_index. depth == 1 && self . infcx . tcx . hir . local_def_id ( id) == def_id{
189
+ self . found_type = Some ( arg) ;
190
+ return ; // we can stop visiting now
191
+ }
192
+ }
193
+
162
194
Some ( & rl:: Region :: Static ) |
163
- Some ( & rl:: Region :: EarlyBound ( _, _) ) |
164
- Some ( & rl:: Region :: LateBound ( _, _) ) |
165
195
Some ( & rl:: Region :: Free ( _, _) ) |
166
196
None => {
167
197
debug ! ( "no arg found" ) ;
0 commit comments