@@ -1896,6 +1896,7 @@ pub fn is_must_use_func_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
1896
1896
/// * `|x| { return x }`
1897
1897
/// * `|x| { return x; }`
1898
1898
/// * `|(x, y)| (x, y)`
1899
+ /// * `|[x, y]| [x, y]`
1899
1900
///
1900
1901
/// Consider calling [`is_expr_untyped_identity_function`] or [`is_expr_identity_function`] instead.
1901
1902
fn is_body_identity_function ( cx : & LateContext < ' _ > , func : & Body < ' _ > ) -> bool {
@@ -1906,9 +1907,9 @@ fn is_body_identity_function(cx: &LateContext<'_>, func: &Body<'_>) -> bool {
1906
1907
. get ( pat. hir_id )
1907
1908
. is_some_and ( |mode| matches ! ( mode. 0 , ByRef :: Yes ( _) ) )
1908
1909
{
1909
- // If a tuple `(x, y)` is of type `&(i32, i32 )`, then due to match ergonomics,
1910
- // the inner patterns become references. Don't consider this the identity function
1911
- // as that changes types.
1910
+ // If the parameter is `(x, y)` of type `&(T, T )`, or `[x, y]` of type `&[T; 2]`, then
1911
+ // due to match ergonomics, the inner patterns become references. Don't consider this
1912
+ // the identity function as that changes types.
1912
1913
return false ;
1913
1914
}
1914
1915
@@ -1921,6 +1922,13 @@ fn is_body_identity_function(cx: &LateContext<'_>, func: &Body<'_>) -> bool {
1921
1922
{
1922
1923
pats. iter ( ) . zip ( tup) . all ( |( pat, expr) | check_pat ( cx, pat, expr) )
1923
1924
} ,
1925
+ ( PatKind :: Slice ( before, slice, after) , ExprKind :: Array ( arr) )
1926
+ if slice. is_none ( ) && before. len ( ) + after. len ( ) == arr. len ( ) =>
1927
+ {
1928
+ ( before. iter ( ) . chain ( after) )
1929
+ . zip ( arr)
1930
+ . all ( |( pat, expr) | check_pat ( cx, pat, expr) )
1931
+ } ,
1924
1932
_ => false ,
1925
1933
}
1926
1934
}
0 commit comments