1- use crate :: {
2- method:: probe:: { self , Pick } ,
3- FnCtxt ,
4- } ;
1+ use crate :: method:: probe:: { self , Pick } ;
2+ use crate :: FnCtxt ;
3+
54use hir:: def_id:: DefId ;
65use hir:: HirId ;
76use hir:: ItemKind ;
87use rustc_errors:: Applicability ;
98use rustc_hir as hir;
109use rustc_infer:: infer:: type_variable:: TypeVariableOrigin ;
10+ use rustc_lint:: { ARRAY_INTO_ITER , BOXED_SLICE_INTO_ITER } ;
1111use rustc_middle:: ty:: { self , Ty } ;
1212use rustc_session:: lint:: builtin:: RUST_2021_PRELUDE_COLLISIONS ;
1313use rustc_span:: symbol:: kw:: { Empty , Underscore } ;
@@ -32,22 +32,30 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3232 segment. ident, self_ty, call_expr, self_expr
3333 ) ;
3434
35- // Rust 2021 and later is already using the new prelude
36- if span. at_least_rust_2021 ( ) {
37- return ;
38- }
39-
40- let prelude_or_array_lint = match segment. ident . name {
35+ let ( prelude_or_array_lint, edition) = match segment. ident . name {
4136 // `try_into` was added to the prelude in Rust 2021.
42- sym:: try_into => RUST_2021_PRELUDE_COLLISIONS ,
37+ sym:: try_into if !span . at_least_rust_2021 ( ) => ( RUST_2021_PRELUDE_COLLISIONS , "2021" ) ,
4338 // `into_iter` wasn't added to the prelude,
4439 // but `[T; N].into_iter()` doesn't resolve to IntoIterator::into_iter
4540 // before Rust 2021, which results in the same problem.
4641 // It is only a problem for arrays.
47- sym:: into_iter if let ty:: Array ( ..) = self_ty. kind ( ) => {
48- // In this case, it wasn't really a prelude addition that was the problem.
49- // Instead, the problem is that the array-into_iter hack will no longer apply in Rust 2021.
50- rustc_lint:: ARRAY_INTO_ITER
42+ sym:: into_iter => {
43+ if let ty:: Array ( ..) = self_ty. kind ( )
44+ && !span. at_least_rust_2021 ( )
45+ {
46+ // In this case, it wasn't really a prelude addition that was the problem.
47+ // Instead, the problem is that the array-into_iter hack will no longer apply in Rust 2021.
48+ ( ARRAY_INTO_ITER , "2021" )
49+ } else if self_ty. is_box ( )
50+ && self_ty. boxed_ty ( ) . is_slice ( )
51+ && !span. at_least_rust_2024 ( )
52+ {
53+ // In this case, it wasn't really a prelude addition that was the problem.
54+ // Instead, the problem is that the array-into_iter hack will no longer apply in Rust 2021.
55+ ( BOXED_SLICE_INTO_ITER , "2024" )
56+ } else {
57+ return ;
58+ }
5159 }
5260 _ => return ,
5361 } ;
@@ -81,7 +89,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8189 prelude_or_array_lint,
8290 self_expr. hir_id ,
8391 self_expr. span ,
84- format ! ( "trait method `{}` will become ambiguous in Rust 2021" , segment. ident. name) ,
92+ format ! (
93+ "trait method `{}` will become ambiguous in Rust {edition}" ,
94+ segment. ident. name
95+ ) ,
8596 |lint| {
8697 let sp = self_expr. span ;
8798
@@ -131,7 +142,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
131142 prelude_or_array_lint,
132143 call_expr. hir_id ,
133144 call_expr. span ,
134- format ! ( "trait method `{}` will become ambiguous in Rust 2021" , segment. ident. name) ,
145+ format ! (
146+ "trait method `{}` will become ambiguous in Rust {edition}" ,
147+ segment. ident. name
148+ ) ,
135149 |lint| {
136150 let sp = call_expr. span ;
137151 let trait_name = self . trait_path_or_bare_name (
0 commit comments