@@ -5,7 +5,7 @@ use rustc_ast::Mutability;
5
5
use rustc_errors:: Applicability ;
6
6
use rustc_hir as hir;
7
7
use rustc_middle:: ty:: subst:: InternalSubsts ;
8
- use rustc_middle:: ty:: { Adt , Ref , Ty } ;
8
+ use rustc_middle:: ty:: { Adt , Array , Ref , Ty } ;
9
9
use rustc_session:: lint:: builtin:: RUST_2021_PRELUDE_COLLISIONS ;
10
10
use rustc_span:: symbol:: kw:: Underscore ;
11
11
use rustc_span:: symbol:: { sym, Ident } ;
@@ -38,11 +38,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
38
38
return ;
39
39
}
40
40
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) {
43
46
return ;
44
47
}
45
48
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
+
46
63
// No need to lint if method came from std/core, as that will now be in the prelude
47
64
if matches ! ( self . tcx. crate_name( pick. item. def_id. krate) , sym:: std | sym:: core) {
48
65
return ;
@@ -69,7 +86,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
69
86
// Inherent impls only require not relying on autoref and autoderef in order to
70
87
// ensure that the trait implementation won't be used
71
88
self . tcx . struct_span_lint_hir (
72
- RUST_2021_PRELUDE_COLLISIONS ,
89
+ prelude_or_array_lint ,
73
90
self_expr. hir_id ,
74
91
self_expr. span ,
75
92
|lint| {
@@ -130,7 +147,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
130
147
// trait implementations require full disambiguation to not clash with the new prelude
131
148
// additions (i.e. convert from dot-call to fully-qualified call)
132
149
self . tcx . struct_span_lint_hir (
133
- RUST_2021_PRELUDE_COLLISIONS ,
150
+ prelude_or_array_lint ,
134
151
call_expr. hir_id ,
135
152
call_expr. span ,
136
153
|lint| {
0 commit comments