@@ -3,7 +3,7 @@ use clippy_config::msrvs::{self, Msrv};
3
3
use clippy_utils:: diagnostics:: span_lint_and_sugg;
4
4
use clippy_utils:: source:: snippet_with_applicability;
5
5
use clippy_utils:: ty:: {
6
- implements_trait, implements_trait_with_env, is_copy, make_normalized_projection,
6
+ implements_trait, implements_trait_with_env, is_copy, is_type_lang_item , make_normalized_projection,
7
7
make_normalized_projection_with_regions, normalize_with_regions,
8
8
} ;
9
9
use rustc_errors:: Applicability ;
@@ -20,9 +20,10 @@ pub(super) fn check(
20
20
msrv : & Msrv ,
21
21
enforce_iter_loop_reborrow : bool ,
22
22
) {
23
- let Some ( ( adjust, ty) ) = is_ref_iterable ( cx, self_arg, call_expr, enforce_iter_loop_reborrow) else {
23
+ let Some ( ( adjust, ty) ) = is_ref_iterable ( cx, self_arg, call_expr, enforce_iter_loop_reborrow, msrv ) else {
24
24
return ;
25
25
} ;
26
+
26
27
if let ty:: Array ( _, count) = * ty. peel_refs ( ) . kind ( ) {
27
28
if !ty. is_ref ( ) {
28
29
if !msrv. meets ( msrvs:: ARRAY_INTO_ITERATOR ) {
@@ -109,6 +110,7 @@ fn is_ref_iterable<'tcx>(
109
110
self_arg : & Expr < ' _ > ,
110
111
call_expr : & Expr < ' _ > ,
111
112
enforce_iter_loop_reborrow : bool ,
113
+ msrv : & Msrv ,
112
114
) -> Option < ( AdjustKind , Ty < ' tcx > ) > {
113
115
let typeck = cx. typeck_results ( ) ;
114
116
if let Some ( trait_id) = cx. tcx . get_diagnostic_item ( sym:: IntoIterator )
@@ -128,6 +130,12 @@ fn is_ref_iterable<'tcx>(
128
130
let self_ty = typeck. expr_ty ( self_arg) ;
129
131
let self_is_copy = is_copy ( cx, self_ty) ;
130
132
133
+ if !msrv. meets ( msrvs:: BOX_INTO_ITER )
134
+ && is_type_lang_item ( cx, self_ty. peel_refs ( ) , rustc_hir:: LangItem :: OwnedBox )
135
+ {
136
+ return None ;
137
+ }
138
+
131
139
if adjustments. is_empty ( ) && self_is_copy {
132
140
// Exact type match, already checked earlier
133
141
return Some ( ( AdjustKind :: None , self_ty) ) ;
0 commit comments