@@ -268,7 +268,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
268
268
269
269
let has_lifetimes =
270
270
generic_args. args . iter ( ) . any ( |arg| matches ! ( arg, GenericArg :: Lifetime ( _) ) ) ;
271
- if !generic_args. parenthesized && !has_lifetimes {
271
+ if !generic_args. parenthesized && !has_lifetimes && expected_lifetimes > 0 {
272
272
// Note: these spans are used for diagnostics when they can't be inferred.
273
273
// See rustc_resolve::late::lifetimes::LifetimeContext::add_missing_lifetime_specifiers_label
274
274
let elided_lifetime_span = if generic_args. span . is_empty ( ) {
@@ -286,49 +286,43 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
286
286
. map ( GenericArg :: Lifetime )
287
287
. chain ( generic_args. args . into_iter ( ) )
288
288
. collect ( ) ;
289
- 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
+ {
290
298
let anon_lt_suggestion = vec ! [ "'_" ; expected_lifetimes] . join ( ", " ) ;
291
299
let no_non_lt_args = generic_args. args . len ( ) == expected_lifetimes;
292
300
let no_bindings = generic_args. bindings . is_empty ( ) ;
293
- 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 {
294
302
// If there are no generic args, our suggestion can include the angle brackets.
295
- ( true , path_span . shrink_to_hi ( ) , format ! ( "<{}>" , anon_lt_suggestion) )
303
+ ( true , format ! ( "<{}>" , anon_lt_suggestion) )
296
304
} else {
297
305
// Otherwise we'll insert a `'_, ` right after the opening bracket.
298
- let span = generic_args
299
- . span
300
- . with_lo ( generic_args. span . lo ( ) + BytePos ( 1 ) )
301
- . shrink_to_lo ( ) ;
302
- ( false , span, format ! ( "{}, " , anon_lt_suggestion) )
306
+ ( false , format ! ( "{}, " , anon_lt_suggestion) )
303
307
} ;
304
- match self . anonymous_lifetime_mode {
305
- // In create-parameter mode we error here because we don't want to support
306
- // deprecated impl elision in new features like impl elision and `async fn`,
307
- // both of which work using the `CreateParameter` mode:
308
- //
309
- // impl Foo for std::cell::Ref<u32> // note lack of '_
310
- // async fn foo(_: std::cell::Ref<u32>) { ... }
311
- AnonymousLifetimeMode :: CreateParameter => {
312
- let mut err = struct_span_err ! (
313
- self . sess,
314
- path_span,
315
- E0726 ,
316
- "implicit elided lifetime not allowed here"
317
- ) ;
318
- rustc_errors:: add_elided_lifetime_in_path_suggestion (
319
- & self . sess . source_map ( ) ,
320
- & mut err,
321
- expected_lifetimes,
322
- path_span,
323
- incl_angl_brckt,
324
- insertion_sp,
325
- suggestion,
326
- ) ;
327
- err. note ( "assuming a `'static` lifetime..." ) ;
328
- err. emit ( ) ;
329
- }
330
- AnonymousLifetimeMode :: PassThrough | AnonymousLifetimeMode :: ReportError => { }
331
- }
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 ( ) ;
332
326
}
333
327
}
334
328
0 commit comments