@@ -129,6 +129,7 @@ pub struct LoweringContext<'a> {
129129 // This will always be false unless the `in_band_lifetimes` feature is
130130 // enabled.
131131 is_collecting_in_band_lifetimes : bool ,
132+
132133 // Currently in-scope lifetimes defined in impl headers, fn headers, or HRTB.
133134 // When `is_collectin_in_band_lifetimes` is true, each lifetime is checked
134135 // against this list to see if it is already in-scope, or if a definition
@@ -945,7 +946,7 @@ impl<'a> LoweringContext<'a> {
945946 let span = t. span . shrink_to_lo ( ) ;
946947 let lifetime = match * region {
947948 Some ( ref lt) => self . lower_lifetime ( lt) ,
948- None => self . elided_lifetime ( span) ,
949+ None => self . elided_ref_lifetime ( span) ,
949950 } ;
950951 hir:: TyRptr ( lifetime, self . lower_mt ( mt, itctx) )
951952 }
@@ -1013,7 +1014,8 @@ impl<'a> LoweringContext<'a> {
10131014 }
10141015 } )
10151016 . collect ( ) ;
1016- let lifetime_bound = lifetime_bound. unwrap_or_else ( || self . elided_lifetime ( t. span ) ) ;
1017+ let lifetime_bound =
1018+ lifetime_bound. unwrap_or_else ( || self . elided_dyn_bound ( t. span ) ) ;
10171019 if kind != TraitObjectSyntax :: Dyn {
10181020 self . maybe_lint_bare_trait ( t. span , t. id , false ) ;
10191021 }
@@ -1536,9 +1538,7 @@ impl<'a> LoweringContext<'a> {
15361538 } ;
15371539
15381540 if !parameters. parenthesized && parameters. lifetimes . is_empty ( ) {
1539- parameters. lifetimes = ( 0 ..expected_lifetimes)
1540- . map ( |_| self . elided_lifetime ( path_span) )
1541- . collect ( ) ;
1541+ parameters. lifetimes = self . elided_path_lifetimes ( path_span, expected_lifetimes) ;
15421542 }
15431543
15441544 hir:: PathSegment :: new (
@@ -3999,7 +3999,7 @@ impl<'a> LoweringContext<'a> {
39993999 // The original ID is taken by the `PolyTraitRef`,
40004000 // so the `Ty` itself needs a different one.
40014001 id = self . next_id ( ) ;
4002- hir:: TyTraitObject ( hir_vec ! [ principal] , self . elided_lifetime ( span) )
4002+ hir:: TyTraitObject ( hir_vec ! [ principal] , self . elided_dyn_bound ( span) )
40034003 } else {
40044004 hir:: TyPath ( hir:: QPath :: Resolved ( None , path) )
40054005 }
@@ -4014,7 +4014,29 @@ impl<'a> LoweringContext<'a> {
40144014 } )
40154015 }
40164016
4017- fn elided_lifetime ( & mut self , span : Span ) -> hir:: Lifetime {
4017+ /// Invoked to create the lifetime argument for a type `&T`
4018+ /// with no explicit lifetime.
4019+ fn elided_ref_lifetime ( & mut self , span : Span ) -> hir:: Lifetime {
4020+ self . new_implicit_lifetime ( span)
4021+ }
4022+
4023+ /// Invoked to create the lifetime argument(s) for a path like
4024+ /// `std::cell::Ref<T>`; note that implicit lifetimes in these
4025+ /// sorts of cases are deprecated. This may therefore report a warning or an
4026+ /// error, depending on the mode.
4027+ fn elided_path_lifetimes ( & mut self , span : Span , count : usize ) -> P < [ hir:: Lifetime ] > {
4028+ ( 0 ..count) . map ( |_| self . new_implicit_lifetime ( span) ) . collect ( )
4029+ }
4030+
4031+ /// Invoked to create the lifetime argument(s) for an elided trait object
4032+ /// bound, like the bound in `Box<dyn Debug>`. This method is not invoked
4033+ /// when the bound is written, even if it is written with `'_` like in
4034+ /// `Box<dyn Debug + '_>`. In those cases, `lower_lifetime` is invoked.
4035+ fn elided_dyn_bound ( & mut self , span : Span ) -> hir:: Lifetime {
4036+ self . new_implicit_lifetime ( span)
4037+ }
4038+
4039+ fn new_implicit_lifetime ( & mut self , span : Span ) -> hir:: Lifetime {
40184040 hir:: Lifetime {
40194041 id : self . next_id ( ) . node_id ,
40204042 span,
0 commit comments