@@ -26,7 +26,7 @@ use rustc_lint::{LateContext, LateLintPass};
26
26
use rustc_middle:: mir:: { Rvalue , StatementKind } ;
27
27
use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment , AutoBorrow , AutoBorrowMutability } ;
28
28
use rustc_middle:: ty:: {
29
- self , Binder , BoundVariableKind , EarlyBinder , FnSig , GenericArgKind , List , ParamTy , PredicateKind ,
29
+ self , Binder , BoundVariableKind , Clause , EarlyBinder , FnSig , GenericArgKind , List , ParamTy , PredicateKind ,
30
30
ProjectionPredicate , Ty , TyCtxt , TypeVisitable , TypeckResults ,
31
31
} ;
32
32
use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
@@ -855,14 +855,10 @@ fn walk_parents<'tcx>(
855
855
} else if let Some ( trait_id) = cx. tcx . trait_of_item ( id)
856
856
&& let arg_ty = cx. tcx . erase_regions ( cx. typeck_results ( ) . expr_ty_adjusted ( e) )
857
857
&& let ty:: Ref ( _, sub_ty, _) = * arg_ty. kind ( )
858
- && let subs = match cx
858
+ && let subs = cx
859
859
. typeck_results ( )
860
- . node_substs_opt ( parent. hir_id )
861
- . and_then ( |subs| subs. get ( 1 ..) )
862
- {
863
- Some ( subs) => cx. tcx . mk_substs ( subs. iter ( ) . copied ( ) ) ,
864
- None => cx. tcx . mk_substs ( std:: iter:: empty :: < ty:: subst:: GenericArg < ' _ > > ( ) ) ,
865
- } && let impl_ty = if cx. tcx . fn_sig ( id) . skip_binder ( ) . inputs ( ) [ 0 ] . is_ref ( ) {
860
+ . node_substs_opt ( parent. hir_id ) . map ( |subs| & subs[ 1 ..] ) . unwrap_or_default ( )
861
+ && let impl_ty = if cx. tcx . fn_sig ( id) . skip_binder ( ) . inputs ( ) [ 0 ] . is_ref ( ) {
866
862
// Trait methods taking `&self`
867
863
sub_ty
868
864
} else {
@@ -871,7 +867,11 @@ fn walk_parents<'tcx>(
871
867
} && impl_ty. is_ref ( )
872
868
&& let infcx = cx. tcx . infer_ctxt ( ) . build ( )
873
869
&& infcx
874
- . type_implements_trait ( trait_id, impl_ty, subs, cx. param_env )
870
+ . type_implements_trait (
871
+ trait_id,
872
+ [ impl_ty. into ( ) ] . into_iter ( ) . chain ( subs. iter ( ) . copied ( ) ) ,
873
+ cx. param_env ,
874
+ )
875
875
. must_apply_modulo_regions ( )
876
876
{
877
877
return Some ( Position :: MethodReceiverRefImpl )
@@ -1106,7 +1106,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
1106
1106
let projection_predicates = predicates
1107
1107
. iter ( )
1108
1108
. filter_map ( |predicate| {
1109
- if let PredicateKind :: Projection ( projection_predicate) = predicate. kind ( ) . skip_binder ( ) {
1109
+ if let PredicateKind :: Clause ( Clause :: Projection ( projection_predicate) ) = predicate. kind ( ) . skip_binder ( ) {
1110
1110
Some ( projection_predicate)
1111
1111
} else {
1112
1112
None
@@ -1120,7 +1120,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
1120
1120
if predicates
1121
1121
. iter ( )
1122
1122
. filter_map ( |predicate| {
1123
- if let PredicateKind :: Trait ( trait_predicate) = predicate. kind ( ) . skip_binder ( )
1123
+ if let PredicateKind :: Clause ( Clause :: Trait ( trait_predicate) ) = predicate. kind ( ) . skip_binder ( )
1124
1124
&& trait_predicate. trait_ref . self_ty ( ) == param_ty. to_ty ( cx. tcx )
1125
1125
{
1126
1126
Some ( trait_predicate. trait_ref . def_id )
@@ -1182,7 +1182,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
1182
1182
}
1183
1183
1184
1184
predicates. iter ( ) . all ( |predicate| {
1185
- if let PredicateKind :: Trait ( trait_predicate) = predicate. kind ( ) . skip_binder ( )
1185
+ if let PredicateKind :: Clause ( Clause :: Trait ( trait_predicate) ) = predicate. kind ( ) . skip_binder ( )
1186
1186
&& cx. tcx . is_diagnostic_item ( sym:: IntoIterator , trait_predicate. trait_ref . def_id )
1187
1187
&& let ty:: Param ( param_ty) = trait_predicate. self_ty ( ) . kind ( )
1188
1188
&& let GenericArgKind :: Type ( ty) = substs_with_referent_ty[ param_ty. index as usize ] . unpack ( )
@@ -1333,7 +1333,7 @@ fn replace_types<'tcx>(
1333
1333
let item_def_id = projection_predicate. projection_ty . item_def_id ;
1334
1334
let assoc_item = cx. tcx . associated_item ( item_def_id) ;
1335
1335
let projection = cx. tcx
1336
- . mk_projection ( assoc_item. def_id , cx. tcx . mk_substs_trait ( new_ty, & [ ] ) ) ;
1336
+ . mk_projection ( assoc_item. def_id , cx. tcx . mk_substs_trait ( new_ty, [ ] ) ) ;
1337
1337
1338
1338
if let Ok ( projected_ty) = cx. tcx . try_normalize_erasing_regions ( cx. param_env , projection)
1339
1339
&& substs[ term_param_ty. index as usize ] != ty:: GenericArg :: from ( projected_ty)
0 commit comments