@@ -15,8 +15,7 @@ use rustc_lint::LateContext;
15
15
use rustc_middle:: mir:: Mutability ;
16
16
use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment , OverloadedDeref } ;
17
17
use rustc_middle:: ty:: {
18
- self , ClauseKind , EarlyBinder , GenericArg , GenericArgKind , GenericArgsRef , ParamTy , ProjectionPredicate ,
19
- TraitPredicate , Ty ,
18
+ self , ClauseKind , GenericArg , GenericArgKind , GenericArgsRef , ParamTy , ProjectionPredicate , TraitPredicate , Ty ,
20
19
} ;
21
20
use rustc_span:: { sym, Symbol } ;
22
21
use rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
@@ -387,22 +386,21 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
387
386
if let Some ( ( callee_def_id, call_generic_args, recv, call_args) ) =
388
387
get_callee_generic_args_and_args ( cx, parent_expr)
389
388
{
390
- // FIXME: the `instantiate_identity()` below seems incorrect, since we eventually
391
- // call `tcx.try_instantiate_and_normalize_erasing_regions` further down
392
- // (i.e., we are explicitly not in the identity context).
393
- let fn_sig = cx. tcx . fn_sig ( callee_def_id) . instantiate_identity ( ) . skip_binder ( ) ;
389
+ let bound_fn_sig = cx. tcx . fn_sig ( callee_def_id) ;
390
+ let fn_sig = bound_fn_sig. skip_binder ( ) ;
394
391
if let Some ( arg_index) = recv. into_iter ( ) . chain ( call_args) . position ( |arg| arg. hir_id == expr. hir_id )
395
- && let Some ( param_ty) = fn_sig. inputs ( ) . get ( arg_index )
396
- && let ty:: Param ( ParamTy { index : param_index , ..} ) = param_ty. kind ( )
392
+ && let param_ty = fn_sig. input ( arg_index ) . skip_binder ( )
393
+ && let ty:: Param ( ParamTy { index : param_index , ..} ) = * param_ty. kind ( )
397
394
// https://github.com/rust-lang/rust-clippy/issues/9504 and https://github.com/rust-lang/rust-clippy/issues/10021
398
- && ( * param_index as usize ) < call_generic_args. len ( )
395
+ && ( param_index as usize ) < call_generic_args. len ( )
399
396
{
400
397
if fn_sig
398
+ . skip_binder ( )
401
399
. inputs ( )
402
400
. iter ( )
403
401
. enumerate ( )
404
402
. filter ( |( i, _) | * i != arg_index)
405
- . any ( |( _, ty) | ty. contains ( * param_ty) )
403
+ . any ( |( _, ty) | ty. contains ( param_ty) )
406
404
{
407
405
return false ;
408
406
}
@@ -414,7 +412,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
414
412
. iter ( )
415
413
. filter ( |predicate| {
416
414
if let ClauseKind :: Trait ( trait_predicate) = predicate. kind ( ) . skip_binder ( )
417
- && trait_predicate. trait_ref . self_ty ( ) == * param_ty
415
+ && trait_predicate. trait_ref . self_ty ( ) == param_ty
418
416
{
419
417
true
420
418
} else {
@@ -425,15 +423,15 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
425
423
let new_subst = cx
426
424
. tcx
427
425
. mk_args_from_iter ( call_generic_args. iter ( ) . enumerate ( ) . map ( |( i, t) | {
428
- if i == ( * param_index as usize ) {
426
+ if i == param_index as usize {
429
427
GenericArg :: from ( ty)
430
428
} else {
431
429
t
432
430
}
433
431
} ) ) ;
434
432
435
433
if trait_predicates. any ( |predicate| {
436
- let predicate = EarlyBinder :: bind ( predicate) . instantiate ( cx. tcx , new_subst) ;
434
+ let predicate = bound_fn_sig . rebind ( predicate) . instantiate ( cx. tcx , new_subst) ;
437
435
let obligation = Obligation :: new ( cx. tcx , ObligationCause :: dummy ( ) , cx. param_env , predicate) ;
438
436
!cx. tcx
439
437
. infer_ctxt ( )
@@ -443,12 +441,12 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
443
441
return false ;
444
442
}
445
443
446
- let output_ty = fn_sig. output ( ) ;
447
- if output_ty. contains ( * param_ty) {
444
+ let output_ty = cx . tcx . instantiate_bound_regions_with_erased ( fn_sig. output ( ) ) ;
445
+ if output_ty. contains ( param_ty) {
448
446
if let Ok ( new_ty) = cx. tcx . try_instantiate_and_normalize_erasing_regions (
449
447
new_subst,
450
448
cx. param_env ,
451
- EarlyBinder :: bind ( output_ty) ,
449
+ bound_fn_sig . rebind ( output_ty) ,
452
450
) {
453
451
expr = parent_expr;
454
452
ty = new_ty;
0 commit comments