Skip to content

Commit c3607bd

Browse files
Use helper function for searching allow_internal_unstable
1 parent ed6c7ef commit c3607bd

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

compiler/rustc_mir/src/transform/check_consts/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
//! has interior mutability or needs to be dropped, as well as the visitor that emits errors when
55
//! it finds operations that are invalid in a certain context.
66
7+
use rustc_attr as attr;
78
use rustc_hir as hir;
89
use rustc_hir::def_id::{DefId, LocalDefId};
910
use rustc_middle::mir;
1011
use rustc_middle::ty::{self, TyCtxt};
12+
use rustc_span::Symbol;
1113

1214
pub use self::qualifs::Qualif;
1315

@@ -55,3 +57,9 @@ impl ConstCx<'mir, 'tcx> {
5557
pub fn is_lang_panic_fn(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
5658
Some(def_id) == tcx.lang_items().panic_fn() || Some(def_id) == tcx.lang_items().begin_panic_fn()
5759
}
60+
61+
pub fn allow_internal_unstable(tcx: TyCtxt<'tcx>, def_id: DefId, feature_gate: Symbol) -> bool {
62+
let attrs = tcx.get_attrs(def_id);
63+
attr::allow_internal_unstable(&tcx.sess, attrs)
64+
.map_or(false, |mut features| features.any(|name| name == feature_gate))
65+
}

compiler/rustc_mir/src/transform/qualify_min_const_fn.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_attr as attr;
21
use rustc_hir as hir;
32
use rustc_hir::def_id::DefId;
43
use rustc_middle::mir::*;
@@ -344,8 +343,7 @@ fn feature_allowed(tcx: TyCtxt<'tcx>, def_id: DefId, feature_gate: Symbol) -> bo
344343

345344
// However, we cannot allow stable `const fn`s to use unstable features without an explicit
346345
// opt-in via `allow_internal_unstable`.
347-
attr::allow_internal_unstable(&tcx.sess, &tcx.get_attrs(def_id))
348-
.map_or(false, |mut features| features.any(|name| name == feature_gate))
346+
super::check_consts::allow_internal_unstable(tcx, def_id, feature_gate)
349347
}
350348

351349
/// Returns `true` if the given library feature gate is allowed within the function with the given `DefId`.
@@ -364,8 +362,7 @@ pub fn lib_feature_allowed(tcx: TyCtxt<'tcx>, def_id: DefId, feature_gate: Symbo
364362

365363
// However, we cannot allow stable `const fn`s to use unstable features without an explicit
366364
// opt-in via `allow_internal_unstable`.
367-
attr::allow_internal_unstable(&tcx.sess, &tcx.get_attrs(def_id))
368-
.map_or(false, |mut features| features.any(|name| name == feature_gate))
365+
super::check_consts::allow_internal_unstable(tcx, def_id, feature_gate)
369366
}
370367

371368
fn check_terminator(

0 commit comments

Comments
 (0)