@@ -5,7 +5,7 @@ use rustc_ast::Mutability;
55use rustc_errors:: Applicability ;
66use rustc_hir as hir;
77use rustc_middle:: ty:: subst:: InternalSubsts ;
8- use rustc_middle:: ty:: { Adt , Ref , Ty } ;
8+ use rustc_middle:: ty:: { Adt , Array , Ref , Ty } ;
99use rustc_session:: lint:: builtin:: RUST_2021_PRELUDE_COLLISIONS ;
1010use rustc_span:: symbol:: kw:: Underscore ;
1111use rustc_span:: symbol:: { sym, Ident } ;
@@ -38,11 +38,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3838 return ;
3939 }
4040
41- // These are the method names that were added to prelude in Rust 2021
42- if !matches ! ( segment. ident. name, sym:: try_into) {
41+ // `try_into` was added to the prelude in Rust 2021.
42+ // `into_iter` wasn't, but `[T; N].into_iter()` doesn't resolve to
43+ // IntoIterator::into_iter before Rust 2021, which results in the same
44+ // problem.
45+ if !matches ! ( segment. ident. name, sym:: try_into | sym:: into_iter) {
4346 return ;
4447 }
4548
49+ let prelude_or_array_lint = if segment. ident . name == sym:: into_iter {
50+ // The `into_iter` problem is only a thing for arrays.
51+ if let Array ( ..) = self_ty. kind ( ) {
52+ // In this case, it wasn't really a prelude addition that was the problem.
53+ // Instead, the problem is that the array-into_iter hack will no longer apply in Rust 2021.
54+ rustc_lint:: ARRAY_INTO_ITER
55+ } else {
56+ // No problem in this case.
57+ return ;
58+ }
59+ } else {
60+ RUST_2021_PRELUDE_COLLISIONS
61+ } ;
62+
4663 // No need to lint if method came from std/core, as that will now be in the prelude
4764 if matches ! ( self . tcx. crate_name( pick. item. def_id. krate) , sym:: std | sym:: core) {
4865 return ;
@@ -69,7 +86,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
6986 // Inherent impls only require not relying on autoref and autoderef in order to
7087 // ensure that the trait implementation won't be used
7188 self . tcx . struct_span_lint_hir (
72- RUST_2021_PRELUDE_COLLISIONS ,
89+ prelude_or_array_lint ,
7390 self_expr. hir_id ,
7491 self_expr. span ,
7592 |lint| {
@@ -130,7 +147,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
130147 // trait implementations require full disambiguation to not clash with the new prelude
131148 // additions (i.e. convert from dot-call to fully-qualified call)
132149 self . tcx . struct_span_lint_hir (
133- RUST_2021_PRELUDE_COLLISIONS ,
150+ prelude_or_array_lint ,
134151 call_expr. hir_id ,
135152 call_expr. span ,
136153 |lint| {
0 commit comments