File tree 1 file changed +14
-1
lines changed
src/librustc_mir/transform
1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -281,8 +281,21 @@ fn check_place(
281
281
Ok ( ( ) )
282
282
}
283
283
284
- /// Returns whether `allow_internal_unstable(..., <feature_gate>, ...)` is present .
284
+ /// Returns `true` if the given feature gate is allowed within the function with the given `DefId` .
285
285
fn feature_allowed ( tcx : TyCtxt < ' tcx > , def_id : DefId , feature_gate : Symbol ) -> bool {
286
+ // All features require that the corresponding gate be enabled.
287
+ if !tcx. features ( ) . enabled ( feature_gate) {
288
+ return false ;
289
+ }
290
+
291
+ // If this crate is not using stability attributes, or this function is not claiming to be a
292
+ // stable `const fn`, that is all that is required.
293
+ if !tcx. features ( ) . staged_api || tcx. has_attr ( def_id, sym:: rustc_const_unstable) {
294
+ return true ;
295
+ }
296
+
297
+ // However, we cannot allow stable `const fn`s to use unstable features without an explicit
298
+ // opt-in via `allow_internal_unstable`.
286
299
attr:: allow_internal_unstable ( & tcx. get_attrs ( def_id) , & tcx. sess . diagnostic ( ) )
287
300
. map_or ( false , |mut features| features. any ( |name| name == feature_gate) )
288
301
}
You can’t perform that action at this time.
0 commit comments