@@ -26,7 +26,7 @@ use rustc_lint::{LateContext, LateLintPass};
2626use rustc_middle:: mir:: { Rvalue , StatementKind } ;
2727use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment , AutoBorrow , AutoBorrowMutability } ;
2828use rustc_middle:: ty:: {
29- self , Binder , BoundVariableKind , EarlyBinder , FnSig , GenericArgKind , List , ParamTy , PredicateKind ,
29+ self , Binder , BoundVariableKind , Clause , EarlyBinder , FnSig , GenericArgKind , List , ParamTy , PredicateKind ,
3030 ProjectionPredicate , Ty , TyCtxt , TypeVisitable , TypeckResults ,
3131} ;
3232use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
@@ -855,14 +855,10 @@ fn walk_parents<'tcx>(
855855 } else if let Some ( trait_id) = cx. tcx . trait_of_item ( id)
856856 && let arg_ty = cx. tcx . erase_regions ( cx. typeck_results ( ) . expr_ty_adjusted ( e) )
857857 && let ty:: Ref ( _, sub_ty, _) = * arg_ty. kind ( )
858- && let subs = match cx
858+ && let subs = cx
859859 . 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 ( ) {
866862 // Trait methods taking `&self`
867863 sub_ty
868864 } else {
@@ -871,7 +867,11 @@ fn walk_parents<'tcx>(
871867 } && impl_ty. is_ref ( )
872868 && let infcx = cx. tcx . infer_ctxt ( ) . build ( )
873869 && 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+ )
875875 . must_apply_modulo_regions ( )
876876 {
877877 return Some ( Position :: MethodReceiverRefImpl )
@@ -1106,7 +1106,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
11061106 let projection_predicates = predicates
11071107 . iter ( )
11081108 . 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 ( ) {
11101110 Some ( projection_predicate)
11111111 } else {
11121112 None
@@ -1120,7 +1120,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
11201120 if predicates
11211121 . iter ( )
11221122 . 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 ( )
11241124 && trait_predicate. trait_ref . self_ty ( ) == param_ty. to_ty ( cx. tcx )
11251125 {
11261126 Some ( trait_predicate. trait_ref . def_id )
@@ -1182,7 +1182,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
11821182 }
11831183
11841184 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 ( )
11861186 && cx. tcx . is_diagnostic_item ( sym:: IntoIterator , trait_predicate. trait_ref . def_id )
11871187 && let ty:: Param ( param_ty) = trait_predicate. self_ty ( ) . kind ( )
11881188 && let GenericArgKind :: Type ( ty) = substs_with_referent_ty[ param_ty. index as usize ] . unpack ( )
@@ -1333,7 +1333,7 @@ fn replace_types<'tcx>(
13331333 let item_def_id = projection_predicate. projection_ty . item_def_id ;
13341334 let assoc_item = cx. tcx . associated_item ( item_def_id) ;
13351335 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, [ ] ) ) ;
13371337
13381338 if let Ok ( projected_ty) = cx. tcx . try_normalize_erasing_regions ( cx. param_env , projection)
13391339 && substs[ term_param_ty. index as usize ] != ty:: GenericArg :: from ( projected_ty)
0 commit comments