@@ -3,7 +3,7 @@ use clippy_config::msrvs::{self, Msrv};
33use clippy_utils:: diagnostics:: span_lint_and_sugg;
44use clippy_utils:: source:: snippet_with_applicability;
55use 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,
77 make_normalized_projection_with_regions, normalize_with_regions,
88} ;
99use rustc_errors:: Applicability ;
@@ -20,9 +20,10 @@ pub(super) fn check(
2020 msrv : & Msrv ,
2121 enforce_iter_loop_reborrow : bool ,
2222) {
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 {
2424 return ;
2525 } ;
26+
2627 if let ty:: Array ( _, count) = * ty. peel_refs ( ) . kind ( ) {
2728 if !ty. is_ref ( ) {
2829 if !msrv. meets ( msrvs:: ARRAY_INTO_ITERATOR ) {
@@ -109,6 +110,7 @@ fn is_ref_iterable<'tcx>(
109110 self_arg : & Expr < ' _ > ,
110111 call_expr : & Expr < ' _ > ,
111112 enforce_iter_loop_reborrow : bool ,
113+ msrv : & Msrv ,
112114) -> Option < ( AdjustKind , Ty < ' tcx > ) > {
113115 let typeck = cx. typeck_results ( ) ;
114116 if let Some ( trait_id) = cx. tcx . get_diagnostic_item ( sym:: IntoIterator )
@@ -128,6 +130,12 @@ fn is_ref_iterable<'tcx>(
128130 let self_ty = typeck. expr_ty ( self_arg) ;
129131 let self_is_copy = is_copy ( cx, self_ty) ;
130132
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+
131139 if adjustments. is_empty ( ) && self_is_copy {
132140 // Exact type match, already checked earlier
133141 return Some ( ( AdjustKind :: None , self_ty) ) ;
0 commit comments