@@ -7,8 +7,6 @@ use rustc_hir as hir;
7
7
use rustc_hir:: def:: { DefKind , PartialRes , Res } ;
8
8
use rustc_hir:: def_id:: DefId ;
9
9
use rustc_hir:: GenericArg ;
10
- use rustc_session:: lint:: builtin:: ELIDED_LIFETIMES_IN_PATHS ;
11
- use rustc_session:: lint:: BuiltinLintDiagnostics ;
12
10
use rustc_span:: symbol:: Ident ;
13
11
use rustc_span:: { BytePos , Span , DUMMY_SP } ;
14
12
@@ -270,12 +268,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
270
268
271
269
let has_lifetimes =
272
270
generic_args. args . iter ( ) . any ( |arg| matches ! ( arg, GenericArg :: Lifetime ( _) ) ) ;
273
- if !generic_args. parenthesized && !has_lifetimes {
271
+ if !generic_args. parenthesized && !has_lifetimes && expected_lifetimes > 0 {
274
272
// Note: these spans are used for diagnostics when they can't be inferred.
275
273
// See rustc_resolve::late::lifetimes::LifetimeContext::add_missing_lifetime_specifiers_label
276
274
let elided_lifetime_span = if generic_args. span . is_empty ( ) {
277
275
// If there are no brackets, use the identifier span.
278
- segment . ident . span
276
+ path_span
279
277
} else if generic_args. is_empty ( ) {
280
278
// If there are brackets, but not generic arguments, then use the opening bracket
281
279
generic_args. span . with_hi ( generic_args. span . lo ( ) + BytePos ( 1 ) )
@@ -284,67 +282,47 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
284
282
generic_args. span . with_lo ( generic_args. span . lo ( ) + BytePos ( 1 ) ) . shrink_to_lo ( )
285
283
} ;
286
284
generic_args. args = self
287
- . elided_path_lifetimes ( elided_lifetime_span, expected_lifetimes)
285
+ . elided_path_lifetimes ( elided_lifetime_span, expected_lifetimes, param_mode )
288
286
. map ( GenericArg :: Lifetime )
289
287
. chain ( generic_args. args . into_iter ( ) )
290
288
. collect ( ) ;
291
- if expected_lifetimes > 0 && param_mode == ParamMode :: Explicit {
289
+ // In create-parameter mode we error here because we don't want to support
290
+ // deprecated impl elision in new features like impl elision and `async fn`,
291
+ // both of which work using the `CreateParameter` mode:
292
+ //
293
+ // impl Foo for std::cell::Ref<u32> // note lack of '_
294
+ // async fn foo(_: std::cell::Ref<u32>) { ... }
295
+ if let ( ParamMode :: Explicit , AnonymousLifetimeMode :: CreateParameter ) =
296
+ ( param_mode, self . anonymous_lifetime_mode )
297
+ {
292
298
let anon_lt_suggestion = vec ! [ "'_" ; expected_lifetimes] . join ( ", " ) ;
293
299
let no_non_lt_args = generic_args. args . len ( ) == expected_lifetimes;
294
300
let no_bindings = generic_args. bindings . is_empty ( ) ;
295
- let ( incl_angl_brckt, insertion_sp , suggestion) = if no_non_lt_args && no_bindings {
301
+ let ( incl_angl_brckt, suggestion) = if no_non_lt_args && no_bindings {
296
302
// If there are no generic args, our suggestion can include the angle brackets.
297
- ( true , path_span . shrink_to_hi ( ) , format ! ( "<{}>" , anon_lt_suggestion) )
303
+ ( true , format ! ( "<{}>" , anon_lt_suggestion) )
298
304
} else {
299
305
// Otherwise we'll insert a `'_, ` right after the opening bracket.
300
- let span = generic_args
301
- . span
302
- . with_lo ( generic_args. span . lo ( ) + BytePos ( 1 ) )
303
- . shrink_to_lo ( ) ;
304
- ( false , span, format ! ( "{}, " , anon_lt_suggestion) )
306
+ ( false , format ! ( "{}, " , anon_lt_suggestion) )
305
307
} ;
306
- match self . anonymous_lifetime_mode {
307
- // In create-parameter mode we error here because we don't want to support
308
- // deprecated impl elision in new features like impl elision and `async fn`,
309
- // both of which work using the `CreateParameter` mode:
310
- //
311
- // impl Foo for std::cell::Ref<u32> // note lack of '_
312
- // async fn foo(_: std::cell::Ref<u32>) { ... }
313
- AnonymousLifetimeMode :: CreateParameter => {
314
- let mut err = struct_span_err ! (
315
- self . sess,
316
- path_span,
317
- E0726 ,
318
- "implicit elided lifetime not allowed here"
319
- ) ;
320
- rustc_errors:: add_elided_lifetime_in_path_suggestion (
321
- & self . sess . source_map ( ) ,
322
- & mut err,
323
- expected_lifetimes,
324
- path_span,
325
- incl_angl_brckt,
326
- insertion_sp,
327
- suggestion,
328
- ) ;
329
- err. note ( "assuming a `'static` lifetime..." ) ;
330
- err. emit ( ) ;
331
- }
332
- AnonymousLifetimeMode :: PassThrough | AnonymousLifetimeMode :: ReportError => {
333
- self . resolver . lint_buffer ( ) . buffer_lint_with_diagnostic (
334
- ELIDED_LIFETIMES_IN_PATHS ,
335
- CRATE_NODE_ID ,
336
- path_span,
337
- "hidden lifetime parameters in types are deprecated" ,
338
- BuiltinLintDiagnostics :: ElidedLifetimesInPaths (
339
- expected_lifetimes,
340
- path_span,
341
- incl_angl_brckt,
342
- insertion_sp,
343
- suggestion,
344
- ) ,
345
- ) ;
346
- }
347
- }
308
+ let insertion_sp = elided_lifetime_span. shrink_to_hi ( ) ;
309
+ let mut err = struct_span_err ! (
310
+ self . sess,
311
+ path_span,
312
+ E0726 ,
313
+ "implicit elided lifetime not allowed here"
314
+ ) ;
315
+ rustc_errors:: add_elided_lifetime_in_path_suggestion (
316
+ & self . sess . source_map ( ) ,
317
+ & mut err,
318
+ expected_lifetimes,
319
+ path_span,
320
+ incl_angl_brckt,
321
+ insertion_sp,
322
+ suggestion,
323
+ ) ;
324
+ err. note ( "assuming a `'static` lifetime..." ) ;
325
+ err. emit ( ) ;
348
326
}
349
327
}
350
328
0 commit comments