@@ -15,8 +15,7 @@ use rustc_lint::LateContext;
1515use rustc_middle:: mir:: Mutability ;
1616use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment , OverloadedDeref } ;
1717use 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 ,
2019} ;
2120use rustc_span:: { sym, Symbol } ;
2221use rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
@@ -359,6 +358,7 @@ fn get_input_traits_and_projections<'tcx>(
359358 ( trait_predicates, projection_predicates)
360359}
361360
361+ #[ expect( clippy:: too_many_lines) ]
362362fn can_change_type < ' a > ( cx : & LateContext < ' a > , mut expr : & ' a Expr < ' a > , mut ty : Ty < ' a > ) -> bool {
363363 for ( _, node) in cx. tcx . hir ( ) . parent_iter ( expr. hir_id ) {
364364 match node {
@@ -387,22 +387,21 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
387387 if let Some ( ( callee_def_id, call_generic_args, recv, call_args) ) =
388388 get_callee_generic_args_and_args ( cx, parent_expr)
389389 {
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 ( ) ;
390+ let bound_fn_sig = cx. tcx . fn_sig ( callee_def_id) ;
391+ let fn_sig = bound_fn_sig. skip_binder ( ) ;
394392 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 ( )
393+ && let param_ty = fn_sig. input ( arg_index ) . skip_binder ( )
394+ && let ty:: Param ( ParamTy { index : param_index , ..} ) = * param_ty. kind ( )
397395 // 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 ( )
396+ && ( param_index as usize ) < call_generic_args. len ( )
399397 {
400398 if fn_sig
399+ . skip_binder ( )
401400 . inputs ( )
402401 . iter ( )
403402 . enumerate ( )
404403 . filter ( |( i, _) | * i != arg_index)
405- . any ( |( _, ty) | ty. contains ( * param_ty) )
404+ . any ( |( _, ty) | ty. contains ( param_ty) )
406405 {
407406 return false ;
408407 }
@@ -414,7 +413,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
414413 . iter ( )
415414 . filter ( |predicate| {
416415 if let ClauseKind :: Trait ( trait_predicate) = predicate. kind ( ) . skip_binder ( )
417- && trait_predicate. trait_ref . self_ty ( ) == * param_ty
416+ && trait_predicate. trait_ref . self_ty ( ) == param_ty
418417 {
419418 true
420419 } else {
@@ -425,15 +424,15 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
425424 let new_subst = cx
426425 . tcx
427426 . mk_args_from_iter ( call_generic_args. iter ( ) . enumerate ( ) . map ( |( i, t) | {
428- if i == ( * param_index as usize ) {
427+ if i == param_index as usize {
429428 GenericArg :: from ( ty)
430429 } else {
431430 t
432431 }
433432 } ) ) ;
434433
435434 if trait_predicates. any ( |predicate| {
436- let predicate = EarlyBinder :: bind ( predicate) . instantiate ( cx. tcx , new_subst) ;
435+ let predicate = bound_fn_sig . rebind ( predicate) . instantiate ( cx. tcx , new_subst) ;
437436 let obligation = Obligation :: new ( cx. tcx , ObligationCause :: dummy ( ) , cx. param_env , predicate) ;
438437 !cx. tcx
439438 . infer_ctxt ( )
@@ -443,12 +442,12 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
443442 return false ;
444443 }
445444
446- let output_ty = fn_sig. output ( ) ;
447- if output_ty. contains ( * param_ty) {
445+ let output_ty = cx . tcx . instantiate_bound_regions_with_erased ( fn_sig. output ( ) ) ;
446+ if output_ty. contains ( param_ty) {
448447 if let Ok ( new_ty) = cx. tcx . try_instantiate_and_normalize_erasing_regions (
449448 new_subst,
450449 cx. param_env ,
451- EarlyBinder :: bind ( output_ty) ,
450+ bound_fn_sig . rebind ( output_ty) ,
452451 ) {
453452 expr = parent_expr;
454453 ty = new_ty;
0 commit comments