@@ -129,6 +129,7 @@ pub struct LoweringContext<'a> {
129
129
// This will always be false unless the `in_band_lifetimes` feature is
130
130
// enabled.
131
131
is_collecting_in_band_lifetimes : bool ,
132
+
132
133
// Currently in-scope lifetimes defined in impl headers, fn headers, or HRTB.
133
134
// When `is_collectin_in_band_lifetimes` is true, each lifetime is checked
134
135
// against this list to see if it is already in-scope, or if a definition
@@ -945,7 +946,7 @@ impl<'a> LoweringContext<'a> {
945
946
let span = t. span . shrink_to_lo ( ) ;
946
947
let lifetime = match * region {
947
948
Some ( ref lt) => self . lower_lifetime ( lt) ,
948
- None => self . elided_lifetime ( span) ,
949
+ None => self . elided_ref_lifetime ( span) ,
949
950
} ;
950
951
hir:: TyRptr ( lifetime, self . lower_mt ( mt, itctx) )
951
952
}
@@ -1013,7 +1014,8 @@ impl<'a> LoweringContext<'a> {
1013
1014
}
1014
1015
} )
1015
1016
. 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 ) ) ;
1017
1019
if kind != TraitObjectSyntax :: Dyn {
1018
1020
self . maybe_lint_bare_trait ( t. span , t. id , false ) ;
1019
1021
}
@@ -1536,9 +1538,7 @@ impl<'a> LoweringContext<'a> {
1536
1538
} ;
1537
1539
1538
1540
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) ;
1542
1542
}
1543
1543
1544
1544
hir:: PathSegment :: new (
@@ -3999,7 +3999,7 @@ impl<'a> LoweringContext<'a> {
3999
3999
// The original ID is taken by the `PolyTraitRef`,
4000
4000
// so the `Ty` itself needs a different one.
4001
4001
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) )
4003
4003
} else {
4004
4004
hir:: TyPath ( hir:: QPath :: Resolved ( None , path) )
4005
4005
}
@@ -4014,7 +4014,29 @@ impl<'a> LoweringContext<'a> {
4014
4014
} )
4015
4015
}
4016
4016
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 {
4018
4040
hir:: Lifetime {
4019
4041
id : self . next_id ( ) . node_id ,
4020
4042
span,
0 commit comments