@@ -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 _;
@@ -375,6 +374,7 @@ fn get_input_traits_and_projections<'tcx>(
375
374
( trait_predicates, projection_predicates)
376
375
}
377
376
377
+ #[ expect( clippy:: too_many_lines) ]
378
378
fn can_change_type < ' a > ( cx : & LateContext < ' a > , mut expr : & ' a Expr < ' a > , mut ty : Ty < ' a > ) -> bool {
379
379
for ( _, node) in cx. tcx . hir ( ) . parent_iter ( expr. hir_id ) {
380
380
match node {
@@ -403,22 +403,21 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
403
403
if let Some ( ( callee_def_id, call_generic_args, recv, call_args) ) =
404
404
get_callee_generic_args_and_args ( cx, parent_expr)
405
405
{
406
- // FIXME: the `instantiate_identity()` below seems incorrect, since we eventually
407
- // call `tcx.try_instantiate_and_normalize_erasing_regions` further down
408
- // (i.e., we are explicitly not in the identity context).
409
- let fn_sig = cx. tcx . fn_sig ( callee_def_id) . instantiate_identity ( ) . skip_binder ( ) ;
406
+ let bound_fn_sig = cx. tcx . fn_sig ( callee_def_id) ;
407
+ let fn_sig = bound_fn_sig. skip_binder ( ) ;
410
408
if let Some ( arg_index) = recv. into_iter ( ) . chain ( call_args) . position ( |arg| arg. hir_id == expr. hir_id )
411
- && let Some ( param_ty) = fn_sig. inputs ( ) . get ( arg_index )
412
- && let ty:: Param ( ParamTy { index : param_index , ..} ) = param_ty. kind ( )
409
+ && let param_ty = fn_sig. input ( arg_index ) . skip_binder ( )
410
+ && let ty:: Param ( ParamTy { index : param_index , ..} ) = * param_ty. kind ( )
413
411
// https://github.com/rust-lang/rust-clippy/issues/9504 and https://github.com/rust-lang/rust-clippy/issues/10021
414
- && ( * param_index as usize ) < call_generic_args. len ( )
412
+ && ( param_index as usize ) < call_generic_args. len ( )
415
413
{
416
414
if fn_sig
415
+ . skip_binder ( )
417
416
. inputs ( )
418
417
. iter ( )
419
418
. enumerate ( )
420
419
. filter ( |( i, _) | * i != arg_index)
421
- . any ( |( _, ty) | ty. contains ( * param_ty) )
420
+ . any ( |( _, ty) | ty. contains ( param_ty) )
422
421
{
423
422
return false ;
424
423
}
@@ -430,7 +429,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
430
429
. iter ( )
431
430
. filter ( |predicate| {
432
431
if let ClauseKind :: Trait ( trait_predicate) = predicate. kind ( ) . skip_binder ( )
433
- && trait_predicate. trait_ref . self_ty ( ) == * param_ty
432
+ && trait_predicate. trait_ref . self_ty ( ) == param_ty
434
433
{
435
434
true
436
435
} else {
@@ -441,15 +440,15 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
441
440
let new_subst = cx
442
441
. tcx
443
442
. mk_args_from_iter ( call_generic_args. iter ( ) . enumerate ( ) . map ( |( i, t) | {
444
- if i == ( * param_index as usize ) {
443
+ if i == param_index as usize {
445
444
GenericArg :: from ( ty)
446
445
} else {
447
446
t
448
447
}
449
448
} ) ) ;
450
449
451
450
if trait_predicates. any ( |predicate| {
452
- let predicate = EarlyBinder :: bind ( predicate) . instantiate ( cx. tcx , new_subst) ;
451
+ let predicate = bound_fn_sig . rebind ( predicate) . instantiate ( cx. tcx , new_subst) ;
453
452
let obligation = Obligation :: new ( cx. tcx , ObligationCause :: dummy ( ) , cx. param_env , predicate) ;
454
453
!cx. tcx
455
454
. infer_ctxt ( )
@@ -459,12 +458,12 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
459
458
return false ;
460
459
}
461
460
462
- let output_ty = fn_sig. output ( ) ;
463
- if output_ty. contains ( * param_ty) {
461
+ let output_ty = cx . tcx . erase_late_bound_regions ( fn_sig. output ( ) ) ;
462
+ if output_ty. contains ( param_ty) {
464
463
if let Ok ( new_ty) = cx. tcx . try_instantiate_and_normalize_erasing_regions (
465
464
new_subst,
466
465
cx. param_env ,
467
- EarlyBinder :: bind ( output_ty) ,
466
+ bound_fn_sig . rebind ( output_ty) ,
468
467
) {
469
468
expr = parent_expr;
470
469
ty = new_ty;
0 commit comments