1
- use crate :: {
2
- method:: probe:: { self , Pick } ,
3
- FnCtxt ,
4
- } ;
1
+ use crate :: method:: probe:: { self , Pick } ;
2
+ use crate :: FnCtxt ;
3
+
5
4
use hir:: def_id:: DefId ;
6
5
use hir:: HirId ;
7
6
use hir:: ItemKind ;
8
7
use rustc_errors:: Applicability ;
9
8
use rustc_hir as hir;
9
+ use rustc_lint:: { ARRAY_INTO_ITER , BOXED_SLICE_INTO_ITER } ;
10
10
use rustc_middle:: span_bug;
11
11
use rustc_middle:: ty:: { self , Ty } ;
12
12
use rustc_session:: lint:: builtin:: RUST_2021_PRELUDE_COLLISIONS ;
@@ -17,7 +17,7 @@ use rustc_trait_selection::infer::InferCtxtExt;
17
17
use std:: fmt:: Write ;
18
18
19
19
impl < ' a , ' tcx > FnCtxt < ' a , ' tcx > {
20
- pub ( super ) fn lint_dot_call_from_2018 (
20
+ pub ( super ) fn lint_edition_dependent_dot_call (
21
21
& self ,
22
22
self_ty : Ty < ' tcx > ,
23
23
segment : & hir:: PathSegment < ' _ > ,
@@ -32,22 +32,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32
32
segment. ident, self_ty, call_expr, self_expr
33
33
) ;
34
34
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 {
41
36
// `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" ) ,
43
38
// `into_iter` wasn't added to the prelude,
44
39
// but `[T; N].into_iter()` doesn't resolve to IntoIterator::into_iter
45
40
// before Rust 2021, which results in the same problem.
46
41
// 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
48
+ // apply in Rust 2021.
49
+ ( ARRAY_INTO_ITER , "2021" )
50
+ } else if self_ty. is_box ( )
51
+ && self_ty. boxed_ty ( ) . is_slice ( )
52
+ && !span. at_least_rust_2024 ( )
53
+ {
54
+ // In this case, it wasn't really a prelude addition that was the problem.
55
+ // Instead, the problem is that the boxed-slice-into_iter hack will no
56
+ // longer apply in Rust 2024.
57
+ ( BOXED_SLICE_INTO_ITER , "2024" )
58
+ } else {
59
+ return ;
60
+ }
51
61
}
52
62
_ => return ,
53
63
} ;
@@ -81,7 +91,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
81
91
prelude_or_array_lint,
82
92
self_expr. hir_id ,
83
93
self_expr. span ,
84
- format ! ( "trait method `{}` will become ambiguous in Rust 2021" , segment. ident. name) ,
94
+ format ! (
95
+ "trait method `{}` will become ambiguous in Rust {edition}" ,
96
+ segment. ident. name
97
+ ) ,
85
98
|lint| {
86
99
let sp = self_expr. span ;
87
100
@@ -131,7 +144,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
131
144
prelude_or_array_lint,
132
145
call_expr. hir_id ,
133
146
call_expr. span ,
134
- format ! ( "trait method `{}` will become ambiguous in Rust 2021" , segment. ident. name) ,
147
+ format ! (
148
+ "trait method `{}` will become ambiguous in Rust {edition}" ,
149
+ segment. ident. name
150
+ ) ,
135
151
|lint| {
136
152
let sp = call_expr. span ;
137
153
let trait_name = self . trait_path_or_bare_name (
0 commit comments