Skip to content

Commit 05f4a9a

Browse files
committed
switch allow_internal_unstable const fns to rustc_allow_const_fn_unstable
1 parent 3948b05 commit 05f4a9a

File tree

24 files changed

+81
-39
lines changed

24 files changed

+81
-39
lines changed

compiler/rustc_attr/src/builtin.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,13 +1013,28 @@ pub fn allow_internal_unstable<'a>(
10131013
sess: &'a Session,
10141014
attrs: &'a [Attribute],
10151015
) -> Option<impl Iterator<Item = Symbol> + 'a> {
1016-
let attrs = sess.filter_by_name(attrs, sym::allow_internal_unstable);
1016+
allow_unstable(sess, attrs, sym::allow_internal_unstable)
1017+
}
1018+
1019+
pub fn rustc_allow_const_fn_unstable<'a>(
1020+
sess: &'a Session,
1021+
attrs: &'a [Attribute],
1022+
) -> Option<impl Iterator<Item = Symbol> + 'a> {
1023+
allow_unstable(sess, attrs, sym::rustc_allow_const_fn_unstable)
1024+
}
1025+
1026+
fn allow_unstable<'a>(
1027+
sess: &'a Session,
1028+
attrs: &'a [Attribute],
1029+
symbol: Symbol,
1030+
) -> Option<impl Iterator<Item = Symbol> + 'a> {
1031+
let attrs = sess.filter_by_name(attrs, symbol);
10171032
let list = attrs
10181033
.filter_map(move |attr| {
10191034
attr.meta_item_list().or_else(|| {
10201035
sess.diagnostic().span_err(
10211036
attr.span,
1022-
"`allow_internal_unstable` expects a list of feature names",
1037+
&format!("`{}` expects a list of feature names", symbol.to_ident_string()),
10231038
);
10241039
None
10251040
})
@@ -1029,8 +1044,10 @@ pub fn allow_internal_unstable<'a>(
10291044
Some(list.into_iter().filter_map(move |it| {
10301045
let name = it.ident().map(|ident| ident.name);
10311046
if name.is_none() {
1032-
sess.diagnostic()
1033-
.span_err(it.span(), "`allow_internal_unstable` expects feature names");
1047+
sess.diagnostic().span_err(
1048+
it.span(),
1049+
&format!("`{}` expects feature names", symbol.to_ident_string()),
1050+
);
10341051
}
10351052
name
10361053
}))

compiler/rustc_expand/src/base.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,13 @@ impl SyntaxExtension {
768768
name: Symbol,
769769
attrs: &[ast::Attribute],
770770
) -> SyntaxExtension {
771-
let allow_internal_unstable = attr::allow_internal_unstable(sess, &attrs)
772-
.map(|features| features.collect::<Vec<Symbol>>().into());
771+
let allow_internal_unstable = {
772+
let mut feat_list = Vec::new();
773+
attr::allow_internal_unstable(sess, &attrs).map(|features| feat_list.extend(features));
774+
attr::rustc_allow_const_fn_unstable(sess, &attrs)
775+
.map(|features| feat_list.extend(features));
776+
Some(feat_list.into())
777+
};
773778

774779
let mut local_inner_macros = false;
775780
if let Some(macro_export) = sess.find_by_name(attrs, sym::macro_export) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn is_lang_panic_fn(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
7979

8080
pub fn allow_internal_unstable(tcx: TyCtxt<'tcx>, def_id: DefId, feature_gate: Symbol) -> bool {
8181
let attrs = tcx.get_attrs(def_id);
82-
attr::allow_internal_unstable(&tcx.sess, attrs)
82+
attr::rustc_allow_const_fn_unstable(&tcx.sess, attrs)
8383
.map_or(false, |mut features| features.any(|name| name == feature_gate))
8484
}
8585

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
805805
}
806806

807807
// Calling an unstable function *always* requires that the corresponding gate
808-
// be enabled, even if the function has `#[allow_internal_unstable(the_gate)]`.
808+
// be enabled, even if the function has `#[rustc_allow_const_fn_unstable(the_gate)]`.
809809
if !tcx.features().declared_lib_features.iter().any(|&(sym, _)| sym == gate) {
810810
self.check_op(ops::FnCallUnstable(callee, Some(gate)));
811811
return;
@@ -965,8 +965,8 @@ fn emit_unstable_in_stable_error(ccx: &ConstCx<'_, '_>, span: Span, gate: Symbol
965965
)
966966
.span_suggestion(
967967
attr_span,
968-
"otherwise `#[allow_internal_unstable]` can be used to bypass stability checks",
969-
format!("#[allow_internal_unstable({})]\n", gate),
968+
"otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks",
969+
format!("#[rustc_allow_const_fn_unstable({})]\n", gate),
970970
Applicability::MaybeIncorrect,
971971
)
972972
.emit();

compiler/rustc_passes/src/check_const.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'tcx> CheckConstVisitor<'tcx> {
8787

8888
let is_feature_allowed = |feature_gate| {
8989
// All features require that the corresponding gate be enabled,
90-
// even if the function has `#[allow_internal_unstable(the_gate)]`.
90+
// even if the function has `#[rustc_allow_const_fn_unstable(the_gate)]`.
9191
if !tcx.features().enabled(feature_gate) {
9292
return false;
9393
}
@@ -105,8 +105,8 @@ impl<'tcx> CheckConstVisitor<'tcx> {
105105
}
106106

107107
// However, we cannot allow stable `const fn`s to use unstable features without an explicit
108-
// opt-in via `allow_internal_unstable`.
109-
attr::allow_internal_unstable(&tcx.sess, &tcx.get_attrs(def_id))
108+
// opt-in via `rustc_allow_const_fn_unstable`.
109+
attr::rustc_allow_const_fn_unstable(&tcx.sess, &tcx.get_attrs(def_id))
110110
.map_or(false, |mut features| features.any(|name| name == feature_gate))
111111
};
112112

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#![allow(explicit_outlives_requirements)]
7373
#![allow(incomplete_features)]
7474
#![deny(unsafe_op_in_unsafe_fn)]
75+
#![cfg_attr(not(bootstrap), feature(rustc_allow_const_fn_unstable))]
7576
#![cfg_attr(not(test), feature(generator_trait))]
7677
#![cfg_attr(test, feature(test))]
7778
#![cfg_attr(test, feature(new_uninit))]

library/alloc/src/raw_vec.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ impl<T> RawVec<T, Global> {
150150
impl<T, A: AllocRef> RawVec<T, A> {
151151
/// Like `new`, but parameterized over the choice of allocator for
152152
/// the returned `RawVec`.
153-
#[allow_internal_unstable(const_fn)]
153+
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn))]
154+
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn))]
154155
pub const fn new_in(alloc: A) -> Self {
155156
// `cap: 0` means "unallocated". zero-sized types are ignored.
156157
Self { ptr: Unique::dangling(), cap: 0, alloc }

library/core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#![warn(missing_debug_implementations)]
6464
#![allow(explicit_outlives_requirements)]
6565
#![allow(incomplete_features)]
66+
#![cfg_attr(not(bootstrap), feature(rustc_allow_const_fn_unstable))]
6667
#![feature(allow_internal_unstable)]
6768
#![feature(arbitrary_self_types)]
6869
#![feature(asm)]

library/core/src/num/int_macros.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,7 +2045,8 @@ assert_eq!(
20452045
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
20462046
// SAFETY: const sound because integers are plain old datatypes so we can always
20472047
// transmute them to arrays of bytes
2048-
#[allow_internal_unstable(const_fn_transmute)]
2048+
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn_transmute))]
2049+
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn_transmute))]
20492050
#[inline]
20502051
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
20512052
// SAFETY: integers are plain old datatypes so we can always transmute them to
@@ -2193,7 +2194,8 @@ fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT),
21932194
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
21942195
// SAFETY: const sound because integers are plain old datatypes so we can always
21952196
// transmute to them
2196-
#[allow_internal_unstable(const_fn_transmute)]
2197+
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn_transmute))]
2198+
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn_transmute))]
21972199
#[inline]
21982200
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
21992201
// SAFETY: integers are plain old datatypes so we can always transmute to them

library/core/src/num/uint_macros.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,8 @@ assert_eq!(
18031803
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
18041804
// SAFETY: const sound because integers are plain old datatypes so we can always
18051805
// transmute them to arrays of bytes
1806-
#[allow_internal_unstable(const_fn_transmute)]
1806+
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn_transmute))]
1807+
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn_transmute))]
18071808
#[inline]
18081809
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
18091810
// SAFETY: integers are plain old datatypes so we can always transmute them to
@@ -1951,7 +1952,8 @@ fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT),
19511952
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
19521953
// SAFETY: const sound because integers are plain old datatypes so we can always
19531954
// transmute to them
1954-
#[allow_internal_unstable(const_fn_transmute)]
1955+
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn_transmute))]
1956+
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn_transmute))]
19551957
#[inline]
19561958
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
19571959
// SAFETY: integers are plain old datatypes so we can always transmute to them

0 commit comments

Comments
 (0)