@@ -947,7 +947,6 @@ fn ty_contains_infer(ty: &hir::Ty<'_>) -> bool {
947
947
// If the conditions are met, returns `Some(Position::ImplArg(..))`; otherwise, returns `None`.
948
948
// The "is copyable" condition is to avoid the case where removing the `&` means `e` would have to
949
949
// be moved, but it cannot be.
950
- #[ expect( clippy:: too_many_lines) ]
951
950
fn needless_borrow_impl_arg_position < ' tcx > (
952
951
cx : & LateContext < ' tcx > ,
953
952
parent : & Expr < ' tcx > ,
@@ -959,7 +958,6 @@ fn needless_borrow_impl_arg_position<'tcx>(
959
958
let sized_trait_def_id = cx. tcx . lang_items ( ) . sized_trait ( ) ;
960
959
961
960
let Some ( callee_def_id) = fn_def_id ( cx, parent) else { return Position :: Other ( precedence) } ;
962
- let callee_generics = cx. tcx . generics_of ( callee_def_id) ;
963
961
let substs_with_expr_ty = cx
964
962
. typeck_results ( )
965
963
. node_substs ( if let ExprKind :: Call ( callee, _) = parent. kind {
@@ -1032,54 +1030,29 @@ fn needless_borrow_impl_arg_position<'tcx>(
1032
1030
return false ;
1033
1031
}
1034
1032
1035
- let substs_with_expr_ty = substs_with_expr_ty. split_at ( callee_generics. parent_count ) ;
1036
- let substs_with_referent_ty = substs_with_expr_ty
1037
- . 0
1038
- . iter ( )
1039
- . copied ( )
1040
- . chain (
1041
- callee_generics
1042
- . params
1043
- . iter ( )
1044
- . zip ( substs_with_expr_ty. 1 . iter ( ) )
1045
- . map ( |( param, arg) | {
1046
- if param. index == param_ty. index {
1047
- ty:: GenericArg :: from ( referent_ty)
1048
- } else {
1049
- projection_predicates
1050
- . iter ( )
1051
- . find_map ( |projection_predicate| {
1052
- if let ty:: Term :: Ty ( term_ty) = projection_predicate. term
1053
- && term_ty. is_param ( param. index )
1054
- {
1055
- let item_def_id = projection_predicate. projection_ty . item_def_id ;
1056
- let assoc_item = cx. tcx . associated_item ( item_def_id) ;
1057
- let projection = cx
1058
- . tcx
1059
- . mk_projection ( assoc_item. def_id , cx. tcx . mk_substs_trait ( referent_ty, & [ ] ) ) ;
1060
- let projected_ty = cx. tcx . normalize_erasing_regions ( cx. param_env , projection) ;
1061
- Some ( ty:: GenericArg :: from ( projected_ty) )
1062
- } else {
1063
- None
1064
- }
1065
- } )
1066
- . unwrap_or ( * arg)
1067
- }
1068
- } ) ,
1069
- )
1070
- . collect :: < Vec < _ > > ( ) ;
1033
+ let mut substs_with_referent_ty = substs_with_expr_ty. to_vec ( ) ;
1034
+ substs_with_referent_ty[ param_ty. index as usize ] = ty:: GenericArg :: from ( referent_ty) ;
1035
+ for projection_predicate in & projection_predicates {
1036
+ if let ty:: Term :: Ty ( term_ty) = projection_predicate. term
1037
+ && let ty:: Param ( term_param_ty) = term_ty. kind ( )
1038
+ {
1039
+ let item_def_id = projection_predicate. projection_ty . item_def_id ;
1040
+ let assoc_item = cx. tcx . associated_item ( item_def_id) ;
1041
+ let projection = cx
1042
+ . tcx
1043
+ . mk_projection ( assoc_item. def_id , cx. tcx . mk_substs_trait ( referent_ty, & [ ] ) ) ;
1044
+ let projected_ty = cx. tcx . normalize_erasing_regions ( cx. param_env , projection) ;
1045
+ substs_with_referent_ty[ term_param_ty. index as usize ] = ty:: GenericArg :: from ( projected_ty) ;
1046
+ }
1047
+ }
1071
1048
1072
- let predicates = EarlyBinder ( predicates ) . subst ( cx . tcx , & substs_with_referent_ty ) ;
1073
- if !predicates . iter ( ) . all ( |predicate| {
1049
+ predicates. iter ( ) . all ( |predicate| {
1050
+ let predicate = EarlyBinder ( predicate ) . subst ( cx . tcx , & substs_with_referent_ty ) ;
1074
1051
let obligation = Obligation :: new ( ObligationCause :: dummy ( ) , cx. param_env , predicate) ;
1075
1052
cx. tcx
1076
1053
. infer_ctxt ( )
1077
1054
. enter ( |infcx| infcx. predicate_must_hold_modulo_regions ( & obligation) )
1078
- } ) {
1079
- return false ;
1080
- }
1081
-
1082
- true
1055
+ } )
1083
1056
} ;
1084
1057
1085
1058
let mut needless_borrow = false ;
0 commit comments