@@ -22,6 +22,7 @@ use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
22
22
use rustc_middle:: ty:: GenericParamDefKind ;
23
23
use rustc_middle:: ty:: { self , ToPolyTraitRef , ToPredicate , Ty , TypeFoldable , WithConstness } ;
24
24
use rustc_session:: lint:: builtin:: FUTURE_PRELUDE_COLLISION ;
25
+ use rustc_span:: edition:: Edition ;
25
26
use rustc_span:: symbol:: { sym, Ident } ;
26
27
use rustc_span:: Span ;
27
28
use rustc_trait_selection:: traits;
@@ -199,48 +200,51 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
199
200
let pick =
200
201
self . lookup_probe ( span, segment. ident , self_ty, call_expr, ProbeScope :: TraitsInScope ) ?;
201
202
202
- if let sym:: try_from | sym:: try_into = segment. ident . name {
203
- if let probe:: PickKind :: TraitPick = pick. kind {
204
- if !matches ! ( self . tcx. crate_name( pick. item. def_id. krate) , sym:: std | sym:: core) {
205
- self . tcx . struct_span_lint_hir (
206
- FUTURE_PRELUDE_COLLISION ,
207
- call_expr. hir_id ,
208
- call_expr. span ,
209
- |lint| {
210
- let sp = call_expr. span ;
211
- let trait_name =
212
- self . tcx . def_path_str ( pick. item . container . assert_trait ( ) ) ;
213
-
214
- let mut lint = lint. build ( & format ! (
215
- "trait method `{}` will become ambiguous in Rust 2021" ,
216
- segment. ident. name
217
- ) ) ;
218
-
219
- if let Ok ( self_expr) =
220
- self . sess ( ) . source_map ( ) . span_to_snippet ( self_expr. span )
221
- {
222
- lint. span_suggestion (
223
- sp,
224
- "disambiguate the associated function" ,
225
- format ! (
226
- "{}::{}({})" ,
227
- trait_name, segment. ident. name, self_expr,
228
- ) ,
229
- Applicability :: MachineApplicable ,
230
- ) ;
231
- } else {
232
- lint. span_help (
233
- sp,
234
- & format ! (
235
- "disambiguate the associated function with `{}::{}(...)`" ,
236
- trait_name, segment. ident,
237
- ) ,
238
- ) ;
239
- }
240
-
241
- lint. emit ( ) ;
242
- } ,
243
- ) ;
203
+ if span. edition ( ) < Edition :: Edition2021 {
204
+ if let sym:: try_from | sym:: try_into = segment. ident . name {
205
+ if let probe:: PickKind :: TraitPick = pick. kind {
206
+ if !matches ! ( self . tcx. crate_name( pick. item. def_id. krate) , sym:: std | sym:: core)
207
+ {
208
+ self . tcx . struct_span_lint_hir (
209
+ FUTURE_PRELUDE_COLLISION ,
210
+ call_expr. hir_id ,
211
+ call_expr. span ,
212
+ |lint| {
213
+ let sp = call_expr. span ;
214
+ let trait_name =
215
+ self . tcx . def_path_str ( pick. item . container . assert_trait ( ) ) ;
216
+
217
+ let mut lint = lint. build ( & format ! (
218
+ "trait method `{}` will become ambiguous in Rust 2021" ,
219
+ segment. ident. name
220
+ ) ) ;
221
+
222
+ if let Ok ( self_expr) =
223
+ self . sess ( ) . source_map ( ) . span_to_snippet ( self_expr. span )
224
+ {
225
+ lint. span_suggestion (
226
+ sp,
227
+ "disambiguate the associated function" ,
228
+ format ! (
229
+ "{}::{}({})" ,
230
+ trait_name, segment. ident. name, self_expr,
231
+ ) ,
232
+ Applicability :: MachineApplicable ,
233
+ ) ;
234
+ } else {
235
+ lint. span_help (
236
+ sp,
237
+ & format ! (
238
+ "disambiguate the associated function with `{}::{}(...)`" ,
239
+ trait_name, segment. ident,
240
+ ) ,
241
+ ) ;
242
+ }
243
+
244
+ lint. emit ( ) ;
245
+ } ,
246
+ ) ;
247
+ }
244
248
}
245
249
}
246
250
}
0 commit comments