@@ -213,6 +213,45 @@ impl RegionScope for ElidableRscope {
213213 }
214214}
215215
216+ /// A scope that behaves as an ElidabeRscope with a `'static` default region
217+ /// that should also warn if the `static_in_const` feature is unset.
218+ #[ derive( Copy , Clone ) ]
219+ pub struct StaticRscope < ' a , ' gcx : ' a + ' tcx , ' tcx : ' a > {
220+ tcx : & ' a ty:: TyCtxt < ' a , ' gcx , ' tcx > ,
221+ }
222+
223+ impl < ' a , ' gcx : ' a + ' tcx , ' tcx : ' a > StaticRscope < ' a , ' gcx , ' tcx > {
224+ /// create a new StaticRscope from a reference to the `TyCtxt`
225+ pub fn new ( tcx : & ' a ty:: TyCtxt < ' a , ' gcx , ' tcx > ) -> Self {
226+ StaticRscope { tcx : tcx }
227+ }
228+ }
229+
230+ impl < ' a , ' gcx : ' a + ' tcx , ' tcx : ' a > RegionScope for StaticRscope < ' a , ' gcx , ' tcx > {
231+ fn anon_regions ( & self ,
232+ span : Span ,
233+ count : usize )
234+ -> Result < Vec < ty:: Region > , Option < Vec < ElisionFailureInfo > > > {
235+ if !self . tcx . sess . features . borrow ( ) . static_in_const {
236+ self . tcx
237+ . sess
238+ . struct_span_err ( span,
239+ "this needs a `'static` lifetime or the \
240+ `static_in_const` feature, see #35897")
241+ . emit ( ) ;
242+ }
243+ Ok ( vec ! [ ty:: ReStatic ; count] )
244+ }
245+
246+ fn object_lifetime_default ( & self , span : Span ) -> Option < ty:: Region > {
247+ Some ( self . base_object_lifetime_default ( span) )
248+ }
249+
250+ fn base_object_lifetime_default ( & self , _span : Span ) -> ty:: Region {
251+ ty:: ReStatic
252+ }
253+ }
254+
216255/// A scope in which we generate anonymous, late-bound regions for
217256/// omitted regions. This occurs in function signatures.
218257pub struct BindingRscope {
0 commit comments