@@ -216,56 +216,73 @@ crate fn environment<'a, 'tcx>(
216
216
let node_id = tcx. hir ( ) . as_local_node_id ( def_id) . unwrap ( ) ;
217
217
let node = tcx. hir ( ) . get ( node_id) ;
218
218
219
- let mut is_fn = false ;
220
- let mut is_impl = false ;
221
- match node {
219
+ enum NodeKind {
220
+ TraitImpl ,
221
+ InherentImpl ,
222
+ Fn ,
223
+ Other ,
224
+ } ;
225
+
226
+ let node_kind = match node {
222
227
Node :: TraitItem ( item) => match item. node {
223
- TraitItemKind :: Method ( ..) => is_fn = true ,
224
- _ => ( ) ,
228
+ TraitItemKind :: Method ( ..) => NodeKind :: Fn ,
229
+ _ => NodeKind :: Other ,
225
230
}
226
231
227
232
Node :: ImplItem ( item) => match item. node {
228
- ImplItemKind :: Method ( ..) => is_fn = true ,
229
- _ => ( ) ,
233
+ ImplItemKind :: Method ( ..) => NodeKind :: Fn ,
234
+ _ => NodeKind :: Other ,
230
235
}
231
236
232
237
Node :: Item ( item) => match item. node {
233
- ItemKind :: Impl ( ..) => is_impl = true ,
234
- ItemKind :: Fn ( ..) => is_fn = true ,
235
- _ => ( ) ,
238
+ ItemKind :: Impl ( .., Some ( ..) , _, _) => NodeKind :: TraitImpl ,
239
+ ItemKind :: Impl ( .., None , _, _) => NodeKind :: InherentImpl ,
240
+ ItemKind :: Fn ( ..) => NodeKind :: Fn ,
241
+ _ => NodeKind :: Other ,
236
242
}
237
243
238
244
Node :: ForeignItem ( item) => match item. node {
239
- ForeignItemKind :: Fn ( ..) => is_fn = true ,
240
- _ => ( ) ,
245
+ ForeignItemKind :: Fn ( ..) => NodeKind :: Fn ,
246
+ _ => NodeKind :: Other ,
241
247
}
242
248
243
249
// FIXME: closures?
244
- _ => ( ) ,
245
- }
250
+ _ => NodeKind :: Other ,
251
+ } ;
246
252
247
253
let mut input_tys = FxHashSet :: default ( ) ;
248
254
249
- // In an impl, we assume that the header trait ref and all its constituents
250
- // are well-formed.
251
- if is_impl {
252
- let trait_ref = tcx. impl_trait_ref ( def_id)
253
- . expect ( "not an impl" ) ;
255
+ match node_kind {
256
+ // In a trait impl, we assume that the header trait ref and all its
257
+ // constituents are well-formed.
258
+ NodeKind :: TraitImpl => {
259
+ let trait_ref = tcx. impl_trait_ref ( def_id)
260
+ . expect ( "not an impl" ) ;
254
261
255
- input_tys. extend (
256
- trait_ref. input_types ( ) . flat_map ( |ty| ty. walk ( ) )
257
- ) ;
258
- }
262
+ input_tys. extend (
263
+ trait_ref. input_types ( ) . flat_map ( |ty| ty. walk ( ) )
264
+ ) ;
265
+ }
259
266
260
- // In an fn, we assume that the arguments and all their constituents are
261
- // well-formed.
262
- if is_fn {
263
- let fn_sig = tcx. fn_sig ( def_id) ;
264
- let fn_sig = tcx. liberate_late_bound_regions ( def_id, & fn_sig) ;
267
+ // In an inherent impl, we assume that the receiver type and all its
268
+ // constituents are well-formed.
269
+ NodeKind :: InherentImpl => {
270
+ let self_ty = tcx. type_of ( def_id) ;
271
+ input_tys. extend ( self_ty. walk ( ) ) ;
272
+ }
265
273
266
- input_tys. extend (
267
- fn_sig. inputs ( ) . iter ( ) . flat_map ( |ty| ty. walk ( ) )
268
- ) ;
274
+ // In an fn, we assume that the arguments and all their constituents are
275
+ // well-formed.
276
+ NodeKind :: Fn => {
277
+ let fn_sig = tcx. fn_sig ( def_id) ;
278
+ let fn_sig = tcx. liberate_late_bound_regions ( def_id, & fn_sig) ;
279
+
280
+ input_tys. extend (
281
+ fn_sig. inputs ( ) . iter ( ) . flat_map ( |ty| ty. walk ( ) )
282
+ ) ;
283
+ }
284
+
285
+ NodeKind :: Other => ( ) ,
269
286
}
270
287
271
288
let clauses = clauses. chain (
0 commit comments