@@ -214,36 +214,21 @@ pub fn implements_trait<'tcx>(
214
214
trait_id : DefId ,
215
215
args : & [ GenericArg < ' tcx > ] ,
216
216
) -> bool {
217
- let callee_id = cx
218
- . enclosing_body
219
- . map ( |body| cx. tcx . hir ( ) . body_owner ( body) . owner . to_def_id ( ) ) ;
220
- implements_trait_with_env_from_iter (
221
- cx. tcx ,
222
- cx. param_env ,
223
- ty,
224
- trait_id,
225
- callee_id,
226
- args. iter ( ) . map ( |& x| Some ( x) ) ,
227
- )
217
+ implements_trait_with_env_from_iter ( cx. tcx , cx. param_env , ty, trait_id, None , args. iter ( ) . map ( |& x| Some ( x) ) )
228
218
}
229
219
230
220
/// Same as `implements_trait` but allows using a `ParamEnv` different from the lint context.
221
+ ///
222
+ /// The `callee_id` argument is used to determine whether this is a function call in a `const fn` environment, used for checking const traits.
231
223
pub fn implements_trait_with_env < ' tcx > (
232
224
tcx : TyCtxt < ' tcx > ,
233
225
param_env : ParamEnv < ' tcx > ,
234
226
ty : Ty < ' tcx > ,
235
227
trait_id : DefId ,
236
- callee_id : DefId ,
228
+ callee_id : Option < DefId > ,
237
229
args : & [ GenericArg < ' tcx > ] ,
238
230
) -> bool {
239
- implements_trait_with_env_from_iter (
240
- tcx,
241
- param_env,
242
- ty,
243
- trait_id,
244
- Some ( callee_id) ,
245
- args. iter ( ) . map ( |& x| Some ( x) ) ,
246
- )
231
+ implements_trait_with_env_from_iter ( tcx, param_env, ty, trait_id, callee_id, args. iter ( ) . map ( |& x| Some ( x) ) )
247
232
}
248
233
249
234
/// Same as `implements_trait_from_env` but takes the arguments as an iterator.
@@ -258,6 +243,13 @@ pub fn implements_trait_with_env_from_iter<'tcx>(
258
243
// Clippy shouldn't have infer types
259
244
assert ! ( !ty. has_infer( ) ) ;
260
245
246
+ // If a `callee_id` is passed, then we assert that it is a body owner
247
+ // through calling `body_owner_kind`, which would panic if the callee
248
+ // does not have a body.
249
+ if let Some ( callee_id) = callee_id {
250
+ let _ = tcx. hir ( ) . body_owner_kind ( callee_id) ;
251
+ }
252
+
261
253
let ty = tcx. erase_regions ( ty) ;
262
254
if ty. has_escaping_bound_vars ( ) {
263
255
return false ;
0 commit comments