@@ -213,6 +213,45 @@ impl RegionScope for ElidableRscope {
213
213
}
214
214
}
215
215
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
+ Ok ( vec ! [ ty:: ReStatic ; count] )
236
+ }
237
+
238
+ fn object_lifetime_default ( & self , span : Span ) -> Option < ty:: Region > {
239
+ Some ( self . base_object_lifetime_default ( span) )
240
+ }
241
+
242
+ fn base_object_lifetime_default ( & self , span : Span ) -> ty:: Region {
243
+ if !self . tcx . sess . features . borrow ( ) . static_in_const {
244
+ self . tcx
245
+ . sess
246
+ . struct_span_warn ( span,
247
+ "This needs a `'static` lifetime or the \
248
+ `static_in_const` feature, see #35897")
249
+ . emit ( ) ;
250
+ }
251
+ ty:: ReStatic
252
+ }
253
+ }
254
+
216
255
/// A scope in which we generate anonymous, late-bound regions for
217
256
/// omitted regions. This occurs in function signatures.
218
257
pub struct BindingRscope {
0 commit comments