@@ -27,7 +27,7 @@ pub fn insert_outlives_predicate<'tcx>(
2727) {
2828 // If the `'a` region is bound within the field type itself, we
2929 // don't want to propagate this constraint to the header.
30- if !is_free_region ( outlived_region) {
30+ if !is_free_region ( tcx , outlived_region) {
3131 return ;
3232 }
3333
@@ -120,27 +120,44 @@ pub fn insert_outlives_predicate<'tcx>(
120120 }
121121
122122 UnpackedKind :: Lifetime ( r) => {
123- if !is_free_region ( r) {
123+ if !is_free_region ( tcx , r) {
124124 return ;
125125 }
126126 required_predicates. insert ( ty:: OutlivesPredicate ( kind, outlived_region) ) ;
127127 }
128128 }
129129}
130130
131- fn is_free_region ( region : Region < ' _ > ) -> bool {
131+ fn is_free_region < ' tcx > ( tcx : TyCtxt < ' _ , ' tcx , ' tcx > , region : Region < ' _ > ) -> bool {
132132 // First, screen for regions that might appear in a type header.
133133 match region {
134- // *These* correspond to `T: 'a` relationships where `'a` is
135- // either declared on the type or `'static`:
134+ // These correspond to `T: 'a` relationships:
136135 //
137136 // struct Foo<'a, T> {
138137 // field: &'a T, // this would generate a ReEarlyBound referencing `'a`
139- // field2: &'static T, // this would generate a ReStatic
140138 // }
141139 //
142140 // We care about these, so fall through.
143- RegionKind :: ReStatic | RegionKind :: ReEarlyBound ( _) => true ,
141+ RegionKind :: ReEarlyBound ( _) => true ,
142+
143+ // These correspond to `T: 'static` relationships which can be
144+ // rather surprising. We are therefore putting this behind a
145+ // feature flag:
146+ //
147+ // struct Foo<'a, T> {
148+ // field: &'static T, // this would generate a ReStatic
149+ // }
150+ RegionKind :: ReStatic => {
151+ if tcx
152+ . sess
153+ . features_untracked ( )
154+ . infer_static_outlives_requirements
155+ {
156+ true
157+ } else {
158+ false
159+ }
160+ }
144161
145162 // Late-bound regions can appear in `fn` types:
146163 //
0 commit comments