@@ -3,7 +3,8 @@ use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
3
3
use clippy_utils:: sugg:: has_enclosing_paren;
4
4
use clippy_utils:: ty:: { implements_trait, is_manually_drop, peel_mid_ty_refs} ;
5
5
use clippy_utils:: {
6
- expr_use_ctxt, get_parent_expr, is_block_like, is_lint_allowed, path_to_local, DefinedTy , ExprUseNode ,
6
+ expr_use_ctxt, get_parent_expr, is_block_like, is_lint_allowed, path_to_local, peel_middle_ty_refs, DefinedTy ,
7
+ ExprUseNode ,
7
8
} ;
8
9
use core:: mem;
9
10
use rustc_ast:: util:: parser:: { PREC_PREFIX , PREC_UNAMBIGUOUS } ;
@@ -175,13 +176,15 @@ struct StateData<'tcx> {
175
176
adjusted_ty : Ty < ' tcx > ,
176
177
}
177
178
179
+ #[ derive( Debug ) ]
178
180
struct DerefedBorrow {
179
181
count : usize ,
180
182
msg : & ' static str ,
181
183
stability : TyCoercionStability ,
182
184
for_field_access : Option < Symbol > ,
183
185
}
184
186
187
+ #[ derive( Debug ) ]
185
188
enum State {
186
189
// Any number of deref method calls.
187
190
DerefMethod {
@@ -744,7 +747,7 @@ fn in_postfix_position<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> boo
744
747
}
745
748
}
746
749
747
- #[ derive( Clone , Copy ) ]
750
+ #[ derive( Clone , Copy , Debug ) ]
748
751
enum TyCoercionStability {
749
752
Deref ,
750
753
Reborrow ,
@@ -1042,16 +1045,28 @@ fn report<'tcx>(
1042
1045
return ;
1043
1046
}
1044
1047
1045
- let ( prefix, precedence) = if let Some ( mutability) = mutability
1046
- && !typeck. expr_ty ( expr) . is_ref ( )
1048
+ let ty = typeck. expr_ty ( expr) ;
1049
+
1050
+ // `&&[T; N]`, or `&&..&[T; N]` (src) cannot coerce to `&[T]` (dst).
1051
+ if let ty:: Ref ( _, dst, _) = data. adjusted_ty . kind ( )
1052
+ && dst. is_slice ( )
1047
1053
{
1048
- let prefix = match mutability {
1049
- Mutability :: Not => "&" ,
1050
- Mutability :: Mut => "&mut " ,
1051
- } ;
1052
- ( prefix, PREC_PREFIX )
1053
- } else {
1054
- ( "" , 0 )
1054
+ let ( src, n_src_refs) = peel_middle_ty_refs ( ty) ;
1055
+ if n_src_refs >= 2 && src. is_array ( ) {
1056
+ return ;
1057
+ }
1058
+ }
1059
+
1060
+ let ( prefix, precedence) = match mutability {
1061
+ Some ( mutability) if !ty. is_ref ( ) => {
1062
+ let prefix = match mutability {
1063
+ Mutability :: Not => "&" ,
1064
+ Mutability :: Mut => "&mut " ,
1065
+ } ;
1066
+ ( prefix, PREC_PREFIX )
1067
+ } ,
1068
+ None if !ty. is_ref ( ) && data. adjusted_ty . is_ref ( ) => ( "&" , 0 ) ,
1069
+ _ => ( "" , 0 ) ,
1055
1070
} ;
1056
1071
span_lint_hir_and_then (
1057
1072
cx,
0 commit comments