1
1
use core:: ops:: ControlFlow ;
2
2
3
3
use rustc_hir as hir;
4
- use rustc_hir:: def_id:: LocalDefId ;
4
+ use rustc_hir:: def_id:: { DefId , LocalDefId } ;
5
5
use rustc_hir:: intravisit:: { self , Visitor } ;
6
6
use rustc_middle:: hir:: map:: Map ;
7
7
use rustc_middle:: hir:: nested_filter;
@@ -28,16 +28,15 @@ pub fn find_anon_type<'tcx>(
28
28
tcx : TyCtxt < ' tcx > ,
29
29
generic_param_scope : LocalDefId ,
30
30
region : Region < ' tcx > ,
31
- br : & ty:: BoundRegionKind ,
32
31
) -> Option < ( & ' tcx hir:: Ty < ' tcx > , & ' tcx hir:: FnSig < ' tcx > ) > {
33
32
let anon_reg = tcx. is_suitable_region ( generic_param_scope, region) ?;
34
- let fn_sig = tcx. hir_node_by_def_id ( anon_reg. def_id ) . fn_sig ( ) ?;
33
+ let fn_sig = tcx. hir_node_by_def_id ( anon_reg. scope ) . fn_sig ( ) ?;
35
34
36
35
fn_sig
37
36
. decl
38
37
. inputs
39
38
. iter ( )
40
- . find_map ( |arg| find_component_for_bound_region ( tcx, arg, br ) )
39
+ . find_map ( |arg| find_component_for_bound_region ( tcx, arg, anon_reg . region_def_id ) )
41
40
. map ( |ty| ( ty, fn_sig) )
42
41
}
43
42
@@ -46,9 +45,9 @@ pub fn find_anon_type<'tcx>(
46
45
fn find_component_for_bound_region < ' tcx > (
47
46
tcx : TyCtxt < ' tcx > ,
48
47
arg : & ' tcx hir:: Ty < ' tcx > ,
49
- br : & ty :: BoundRegionKind ,
48
+ region_def_id : DefId ,
50
49
) -> Option < & ' tcx hir:: Ty < ' tcx > > {
51
- FindNestedTypeVisitor { tcx, bound_region : * br , current_index : ty:: INNERMOST }
50
+ FindNestedTypeVisitor { tcx, region_def_id , current_index : ty:: INNERMOST }
52
51
. visit_ty ( arg)
53
52
. break_value ( )
54
53
}
@@ -62,9 +61,8 @@ fn find_component_for_bound_region<'tcx>(
62
61
// specific part of the type in the error message.
63
62
struct FindNestedTypeVisitor < ' tcx > {
64
63
tcx : TyCtxt < ' tcx > ,
65
- // The bound_region corresponding to the Refree(freeregion)
66
- // associated with the anonymous region we are looking for.
67
- bound_region : ty:: BoundRegionKind ,
64
+ // The `DefId` of the region we're looking for.
65
+ region_def_id : DefId ,
68
66
current_index : ty:: DebruijnIndex ,
69
67
}
70
68
@@ -96,48 +94,39 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
96
94
hir:: TyKind :: Ref ( lifetime, _) => {
97
95
// the lifetime of the Ref
98
96
let hir_id = lifetime. hir_id ;
99
- match ( self . tcx . named_bound_var ( hir_id) , self . bound_region ) {
97
+ match self . tcx . named_bound_var ( hir_id) {
100
98
// Find the index of the named region that was part of the
101
99
// error. We will then search the function parameters for a bound
102
100
// region at the right depth with the same index
103
- (
104
- Some ( rbv:: ResolvedArg :: EarlyBound ( id) ) ,
105
- ty:: BoundRegionKind :: Named ( def_id, _) ,
106
- ) => {
107
- debug ! ( "EarlyBound id={:?} def_id={:?}" , id, def_id) ;
108
- if id. to_def_id ( ) == def_id {
101
+ Some ( rbv:: ResolvedArg :: EarlyBound ( id) ) => {
102
+ debug ! ( "EarlyBound id={:?}" , id) ;
103
+ if id. to_def_id ( ) == self . region_def_id {
109
104
return ControlFlow :: Break ( arg) ;
110
105
}
111
106
}
112
107
113
108
// Find the index of the named region that was part of the
114
109
// error. We will then search the function parameters for a bound
115
110
// region at the right depth with the same index
116
- (
117
- Some ( rbv:: ResolvedArg :: LateBound ( debruijn_index, _, id) ) ,
118
- ty:: BoundRegionKind :: Named ( def_id, _) ,
119
- ) => {
111
+ Some ( rbv:: ResolvedArg :: LateBound ( debruijn_index, _, id) ) => {
120
112
debug ! (
121
113
"FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}" ,
122
114
debruijn_index
123
115
) ;
124
- debug ! ( "LateBound id={:?} def_id={:?}" , id, def_id) ;
125
- if debruijn_index == self . current_index && id. to_def_id ( ) == def_id {
116
+ debug ! ( "LateBound id={:?}" , id) ;
117
+ if debruijn_index == self . current_index
118
+ && id. to_def_id ( ) == self . region_def_id
119
+ {
126
120
return ControlFlow :: Break ( arg) ;
127
121
}
128
122
}
129
123
130
- (
131
- Some (
132
- rbv:: ResolvedArg :: StaticLifetime
133
- | rbv:: ResolvedArg :: Free ( _, _)
134
- | rbv:: ResolvedArg :: EarlyBound ( _)
135
- | rbv:: ResolvedArg :: LateBound ( _, _, _)
136
- | rbv:: ResolvedArg :: Error ( _) ,
137
- )
138
- | None ,
139
- _,
140
- ) => {
124
+ Some (
125
+ rbv:: ResolvedArg :: StaticLifetime
126
+ | rbv:: ResolvedArg :: Free ( _, _)
127
+ | rbv:: ResolvedArg :: Error ( _) ,
128
+ )
129
+ | None => {
141
130
debug ! ( "no arg found" ) ;
142
131
}
143
132
}
@@ -151,7 +140,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
151
140
return if intravisit:: walk_ty (
152
141
& mut TyPathVisitor {
153
142
tcx : self . tcx ,
154
- bound_region : self . bound_region ,
143
+ region_def_id : self . region_def_id ,
155
144
current_index : self . current_index ,
156
145
} ,
157
146
arg,
@@ -179,7 +168,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
179
168
// specific part of the type in the error message.
180
169
struct TyPathVisitor < ' tcx > {
181
170
tcx : TyCtxt < ' tcx > ,
182
- bound_region : ty :: BoundRegionKind ,
171
+ region_def_id : DefId ,
183
172
current_index : ty:: DebruijnIndex ,
184
173
}
185
174
@@ -192,38 +181,29 @@ impl<'tcx> Visitor<'tcx> for TyPathVisitor<'tcx> {
192
181
}
193
182
194
183
fn visit_lifetime ( & mut self , lifetime : & hir:: Lifetime ) -> Self :: Result {
195
- match ( self . tcx . named_bound_var ( lifetime. hir_id ) , self . bound_region ) {
184
+ match self . tcx . named_bound_var ( lifetime. hir_id ) {
196
185
// the lifetime of the TyPath!
197
- ( Some ( rbv:: ResolvedArg :: EarlyBound ( id) ) , ty :: BoundRegionKind :: Named ( def_id , _ ) ) => {
198
- debug ! ( "EarlyBound id={:?} def_id={:?} " , id, def_id ) ;
199
- if id. to_def_id ( ) == def_id {
186
+ Some ( rbv:: ResolvedArg :: EarlyBound ( id) ) => {
187
+ debug ! ( "EarlyBound id={:?}" , id) ;
188
+ if id. to_def_id ( ) == self . region_def_id {
200
189
return ControlFlow :: Break ( ( ) ) ;
201
190
}
202
191
}
203
192
204
- (
205
- Some ( rbv:: ResolvedArg :: LateBound ( debruijn_index, _, id) ) ,
206
- ty:: BoundRegionKind :: Named ( def_id, _) ,
207
- ) => {
193
+ Some ( rbv:: ResolvedArg :: LateBound ( debruijn_index, _, id) ) => {
208
194
debug ! ( "FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}" , debruijn_index, ) ;
209
195
debug ! ( "id={:?}" , id) ;
210
- debug ! ( "def_id={:?}" , def_id) ;
211
- if debruijn_index == self . current_index && id. to_def_id ( ) == def_id {
196
+ if debruijn_index == self . current_index && id. to_def_id ( ) == self . region_def_id {
212
197
return ControlFlow :: Break ( ( ) ) ;
213
198
}
214
199
}
215
200
216
- (
217
- Some (
218
- rbv:: ResolvedArg :: StaticLifetime
219
- | rbv:: ResolvedArg :: EarlyBound ( _)
220
- | rbv:: ResolvedArg :: LateBound ( _, _, _)
221
- | rbv:: ResolvedArg :: Free ( _, _)
222
- | rbv:: ResolvedArg :: Error ( _) ,
223
- )
224
- | None ,
225
- _,
226
- ) => {
201
+ Some (
202
+ rbv:: ResolvedArg :: StaticLifetime
203
+ | rbv:: ResolvedArg :: Free ( _, _)
204
+ | rbv:: ResolvedArg :: Error ( _) ,
205
+ )
206
+ | None => {
227
207
debug ! ( "no arg found" ) ;
228
208
}
229
209
}
0 commit comments