@@ -46,9 +46,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
46
46
} ;
47
47
48
48
// Determine whether the sub and sup consist of both anonymous (elided) regions.
49
- let anon_reg_sup = or_false ! ( self . is_suitable_anonymous_region ( sup) ) ;
49
+ let anon_reg_sup = or_false ! ( self . is_suitable_region ( sup) ) ;
50
50
51
- let anon_reg_sub = or_false ! ( self . is_suitable_anonymous_region ( sub) ) ;
51
+ let anon_reg_sub = or_false ! ( self . is_suitable_region ( sub) ) ;
52
52
let scope_def_id_sup = anon_reg_sup. def_id ;
53
53
let bregion_sup = anon_reg_sup. boundregion ;
54
54
let scope_def_id_sub = anon_reg_sub. def_id ;
@@ -57,10 +57,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
57
57
let ty_sup = or_false ! ( self . find_anon_type( sup, & bregion_sup) ) ;
58
58
59
59
let ty_sub = or_false ! ( self . find_anon_type( sub, & bregion_sub) ) ;
60
+ debug ! ( "try_report_anon_anon_conflict: found_arg1={:?} sup={:?} br1={:?}" ,
61
+ ty_sub,
62
+ sup,
63
+ bregion_sup) ;
64
+ debug ! ( "try_report_anon_anon_conflict: found_arg2={:?} sub={:?} br2={:?}" ,
65
+ ty_sup,
66
+ sub,
67
+ bregion_sub) ;
60
68
61
69
let ( main_label, label1, label2) = if let ( Some ( sup_arg) , Some ( sub_arg) ) =
62
- ( self . find_arg_with_anonymous_region ( sup, sup) ,
63
- self . find_arg_with_anonymous_region ( sub, sub) ) {
70
+ ( self . find_arg_with_region ( sup, sup) , self . find_arg_with_region ( sub, sub) ) {
64
71
65
72
let ( anon_arg_sup, is_first_sup, anon_arg_sub, is_first_sub) =
66
73
( sup_arg. arg , sup_arg. is_first , sub_arg. arg , sub_arg. is_first ) ;
@@ -97,6 +104,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
97
104
( span_label, span_label_var1, span_label_var2)
98
105
}
99
106
} else {
107
+ debug ! ( "no arg with anon region found" ) ;
108
+ debug ! ( "try_report_anon_anon_conflict: is_suitable(sub) = {:?}" ,
109
+ self . is_suitable_region( sub) ) ;
110
+ debug ! ( "try_report_anon_anon_conflict: is_suitable(sup) = {:?}" ,
111
+ self . is_suitable_region( sup) ) ;
100
112
return false ;
101
113
} ;
102
114
@@ -124,35 +136,27 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
124
136
/// The function returns the nested type corresponding to the anonymous region
125
137
/// for e.g. `&u8` and Vec<`&u8`.
126
138
pub fn find_anon_type ( & self , region : Region < ' tcx > , br : & ty:: BoundRegion ) -> Option < & hir:: Ty > {
127
- if let Some ( anon_reg) = self . is_suitable_anonymous_region ( region) {
139
+ if let Some ( anon_reg) = self . is_suitable_region ( region) {
128
140
let def_id = anon_reg. def_id ;
129
141
if let Some ( node_id) = self . tcx . hir . as_local_node_id ( def_id) {
130
- let ret_ty = self . tcx . type_of ( def_id) ;
131
- if let ty:: TyFnDef ( _, _) = ret_ty. sty {
132
- let inputs: & [ _ ] =
133
- match self . tcx . hir . get ( node_id) {
134
- hir_map:: NodeItem ( & hir:: Item {
135
- node : hir:: ItemFn ( ref fndecl, ..) , ..
136
- } ) => & fndecl. inputs ,
137
- hir_map:: NodeTraitItem ( & hir:: TraitItem {
138
- node : hir:: TraitItemKind :: Method ( ref fndecl, ..) ,
139
- ..
140
- } ) => & fndecl. decl . inputs ,
141
- hir_map:: NodeImplItem ( & hir:: ImplItem {
142
- node : hir:: ImplItemKind :: Method ( ref fndecl, ..) ,
143
- ..
144
- } ) => & fndecl. decl . inputs ,
142
+ let inputs: & [ _ ] = match self . tcx . hir . get ( node_id) {
143
+ hir_map:: NodeItem ( & hir:: Item { node : hir:: ItemFn ( ref fndecl, ..) , .. } ) => {
144
+ & fndecl. inputs
145
+ }
146
+ hir_map:: NodeTraitItem ( & hir:: TraitItem {
147
+ node : hir:: TraitItemKind :: Method ( ref fndecl, ..) , ..
148
+ } ) => & fndecl. decl . inputs ,
149
+ hir_map:: NodeImplItem ( & hir:: ImplItem {
150
+ node : hir:: ImplItemKind :: Method ( ref fndecl, ..) , ..
151
+ } ) => & fndecl. decl . inputs ,
145
152
146
- _ => & [ ] ,
147
- } ;
153
+ _ => & [ ] ,
154
+ } ;
148
155
149
- return inputs
150
- . iter ( )
151
- . filter_map ( |arg| {
152
- self . find_component_for_bound_region ( & * * arg, br)
153
- } )
154
- . next ( ) ;
155
- }
156
+ return inputs
157
+ . iter ( )
158
+ . filter_map ( |arg| self . find_component_for_bound_region ( & * * arg, br) )
159
+ . next ( ) ;
156
160
}
157
161
}
158
162
None
@@ -199,30 +203,62 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
199
203
}
200
204
201
205
fn visit_ty ( & mut self , arg : & ' gcx hir:: Ty ) {
202
- // Find the index of the anonymous region that was part of the
203
- // error. We will then search the function parameters for a bound
204
- // region at the right depth with the same index.
205
- let br_index = match self . bound_region {
206
- ty:: BrAnon ( index) => index,
207
- _ => return ,
208
- } ;
209
-
210
206
match arg. node {
211
207
hir:: TyRptr ( ref lifetime, _) => {
208
+ // the lifetime of the TyRptr
212
209
let hir_id = self . infcx . tcx . hir . node_to_hir_id ( lifetime. id ) ;
213
- match self . infcx . tcx . named_region ( hir_id) {
214
- // the lifetime of the TyRptr
215
- Some ( rl:: Region :: LateBoundAnon ( debruijn_index, anon_index) ) => {
210
+ match ( self . infcx . tcx . named_region ( hir_id) , self . bound_region ) {
211
+ // Find the index of the anonymous region that was part of the
212
+ // error. We will then search the function parameters for a bound
213
+ // region at the right depth with the same index
214
+ ( Some ( rl:: Region :: LateBoundAnon ( debruijn_index, anon_index) ) ,
215
+ ty:: BrAnon ( br_index) ) => {
216
+ debug ! ( "LateBoundAnon depth = {:?} anon_index = {:?} br_index={:?}" ,
217
+ debruijn_index. depth,
218
+ anon_index,
219
+ br_index) ;
216
220
if debruijn_index. depth == 1 && anon_index == br_index {
217
221
self . found_type = Some ( arg) ;
218
222
return ; // we can stop visiting now
219
223
}
220
224
}
221
- Some ( rl:: Region :: Static ) |
222
- Some ( rl:: Region :: EarlyBound ( _, _) ) |
223
- Some ( rl:: Region :: LateBound ( _, _) ) |
224
- Some ( rl:: Region :: Free ( _, _) ) |
225
- None => {
225
+
226
+ // Find the index of the named region that was part of the
227
+ // error. We will then search the function parameters for a bound
228
+ // region at the right depth with the same index
229
+ ( Some ( rl:: Region :: EarlyBound ( _, id) ) , ty:: BrNamed ( def_id, _) ) => {
230
+ debug ! ( "EarlyBound self.infcx.tcx.hir.local_def_id(id)={:?} \
231
+ def_id={:?}",
232
+ self . infcx. tcx. hir. local_def_id( id) ,
233
+ def_id) ;
234
+ if self . infcx . tcx . hir . local_def_id ( id) == def_id {
235
+ self . found_type = Some ( arg) ;
236
+ return ; // we can stop visiting now
237
+ }
238
+ }
239
+
240
+ // Find the index of the named region that was part of the
241
+ // error. We will then search the function parameters for a bound
242
+ // region at the right depth with the same index
243
+ ( Some ( rl:: Region :: LateBound ( debruijn_index, id) ) , ty:: BrNamed ( def_id, _) ) => {
244
+ debug ! ( "FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}" ,
245
+ debruijn_index. depth) ;
246
+ debug ! ( "self.infcx.tcx.hir.local_def_id(id)={:?}" ,
247
+ self . infcx. tcx. hir. local_def_id( id) ) ;
248
+ debug ! ( "def_id={:?}" , def_id) ;
249
+ if debruijn_index. depth == 1 &&
250
+ self . infcx . tcx . hir . local_def_id ( id) == def_id {
251
+ self . found_type = Some ( arg) ;
252
+ return ; // we can stop visiting now
253
+ }
254
+ }
255
+
256
+ ( Some ( rl:: Region :: Static ) , _) |
257
+ ( Some ( rl:: Region :: Free ( _, _) ) , _) |
258
+ ( Some ( rl:: Region :: EarlyBound ( _, _) ) , _) |
259
+ ( Some ( rl:: Region :: LateBound ( _, _) ) , _) |
260
+ ( Some ( rl:: Region :: LateBoundAnon ( _, _) ) , _) |
261
+ ( None , _) => {
226
262
debug ! ( "no arg found" ) ;
227
263
}
228
264
}
0 commit comments