@@ -27,7 +27,7 @@ pub fn insert_outlives_predicate<'tcx>(
27
27
) {
28
28
// If the `'a` region is bound within the field type itself, we
29
29
// 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) {
31
31
return ;
32
32
}
33
33
@@ -120,27 +120,44 @@ pub fn insert_outlives_predicate<'tcx>(
120
120
}
121
121
122
122
UnpackedKind :: Lifetime ( r) => {
123
- if !is_free_region ( r) {
123
+ if !is_free_region ( tcx , r) {
124
124
return ;
125
125
}
126
126
required_predicates. insert ( ty:: OutlivesPredicate ( kind, outlived_region) ) ;
127
127
}
128
128
}
129
129
}
130
130
131
- fn is_free_region ( region : Region < ' _ > ) -> bool {
131
+ fn is_free_region < ' tcx > ( tcx : TyCtxt < ' _ , ' tcx , ' tcx > , region : Region < ' _ > ) -> bool {
132
132
// First, screen for regions that might appear in a type header.
133
133
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:
136
135
//
137
136
// struct Foo<'a, T> {
138
137
// field: &'a T, // this would generate a ReEarlyBound referencing `'a`
139
- // field2: &'static T, // this would generate a ReStatic
140
138
// }
141
139
//
142
140
// 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
+ }
144
161
145
162
// Late-bound regions can appear in `fn` types:
146
163
//
0 commit comments