@@ -46,9 +46,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
4646        } ; 
4747
4848        // 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) ) ; 
5050
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) ) ; 
5252        let  scope_def_id_sup = anon_reg_sup. def_id ; 
5353        let  bregion_sup = anon_reg_sup. boundregion ; 
5454        let  scope_def_id_sub = anon_reg_sub. def_id ; 
@@ -57,10 +57,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
5757        let  ty_sup = or_false ! ( self . find_anon_type( sup,  & bregion_sup) ) ; 
5858
5959        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) ; 
6068
6169        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) )  { 
6471
6572            let  ( anon_arg_sup,  is_first_sup,  anon_arg_sub,  is_first_sub)  =
6673                ( 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> {
97104                ( span_label,  span_label_var1,  span_label_var2) 
98105            } 
99106        }  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) ) ; 
100112            return  false ; 
101113        } ; 
102114
@@ -124,35 +136,27 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
124136     /// The function returns the nested type corresponding to the anonymous region 
125137     /// for e.g. `&u8` and Vec<`&u8`. 
126138     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)  { 
128140            let  def_id = anon_reg. def_id ; 
129141            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 , 
145152
146-                              _ => & [ ] , 
147-                          } ; 
153+                     _ => & [ ] , 
154+                 } ; 
148155
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 ( ) ; 
156160            } 
157161        } 
158162        None 
@@ -199,30 +203,62 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
199203    } 
200204
201205    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- 
210206        match  arg. node  { 
211207            hir:: TyRptr ( ref  lifetime,  _)  => { 
208+                 // the lifetime of the TyRptr 
212209                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) ; 
216220                        if  debruijn_index. depth  == 1  && anon_index == br_index { 
217221                            self . found_type  = Some ( arg) ; 
218222                            return ;  // we can stop visiting now 
219223                        } 
220224                    } 
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 ,  _)  => { 
226262                        debug ! ( "no arg found" ) ; 
227263                    } 
228264                } 
0 commit comments