@@ -13,6 +13,7 @@ use rustc_hir::QPath::Resolved;
1313use rustc_hir:: def:: Res ;
1414use rustc_hir:: { Expr , ExprKind , Pat } ;
1515use rustc_lint:: LateContext ;
16+ use rustc_middle:: ty;
1617use rustc_span:: { Spanned , sym} ;
1718
1819use super :: MANUAL_SLICE_FILL ;
@@ -84,6 +85,24 @@ pub(super) fn check<'tcx>(
8485 {
8586 sugg ( cx, body, expr, recv_path. span , assignval. span ) ;
8687 }
88+ // `for slot in s { *slot = value; }` where `s` is already `&mut [T; N]`
89+ else if let ExprKind :: Assign ( assignee, assignval, _) = peel_blocks_with_stmt ( body) . kind
90+ && let ExprKind :: Unary ( UnOp :: Deref , slice_iter) = assignee. kind
91+ && let ExprKind :: Path ( Resolved ( _, slice_path) ) = slice_iter. kind
92+ && let Res :: Local ( local) = slice_path. res
93+ && local == pat. hir_id
94+ && !assignval. span . from_expansion ( )
95+ && switch_to_eager_eval ( cx, assignval)
96+ && !is_local_used ( cx, assignval, local)
97+ && let arg_ty = cx. typeck_results ( ) . expr_ty ( arg)
98+ && let ty:: Ref ( _, inner_ty, rustc_ast:: Mutability :: Mut ) = arg_ty. kind ( )
99+ && is_slice_like ( cx, * inner_ty)
100+ && let Some ( clone_trait) = cx. tcx . lang_items ( ) . clone_trait ( )
101+ && implements_trait ( cx, * inner_ty, clone_trait, & [ ] )
102+ && msrv. meets ( cx, msrvs:: SLICE_FILL )
103+ {
104+ sugg ( cx, body, expr, arg. span , assignval. span ) ;
105+ }
87106}
88107
89108fn sugg < ' tcx > (
0 commit comments