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

+21-4
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

+7-2
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

+1-1
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

+3-3
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

+3-3
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

+1
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

+2-1
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

+1
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

+4-2
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

+4-2
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

library/core/src/slice/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ impl<T> [T] {
8888
#[rustc_const_stable(feature = "const_slice_len", since = "1.32.0")]
8989
#[inline]
9090
// SAFETY: const sound because we transmute out the length field as a usize (which it must be)
91-
#[allow_internal_unstable(const_fn_union)]
91+
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn_union))]
92+
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn_union))]
9293
pub const fn len(&self) -> usize {
9394
// SAFETY: this is safe because `&[T]` and `FatPtr<T>` have the same layout.
9495
// Only `std` can make this guarantee.

library/core/src/str/converts.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ pub fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error> {
157157
#[inline]
158158
#[stable(feature = "rust1", since = "1.0.0")]
159159
#[rustc_const_unstable(feature = "const_str_from_utf8_unchecked", issue = "75196")]
160-
#[allow_internal_unstable(const_fn_transmute)]
160+
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn_transmute))]
161+
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn_transmute))]
161162
pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str {
162163
// SAFETY: the caller must guarantee that the bytes `v` are valid UTF-8.
163164
// Also relies on `&str` and `&[u8]` having the same layout.

library/core/src/str/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ impl str {
219219
#[rustc_const_stable(feature = "str_as_bytes", since = "1.32.0")]
220220
#[inline(always)]
221221
#[allow(unused_attributes)]
222-
#[allow_internal_unstable(const_fn_transmute)]
222+
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn_transmute))]
223+
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn_transmute))]
223224
pub const fn as_bytes(&self) -> &[u8] {
224225
// SAFETY: const sound because we transmute two types with the same layout
225226
unsafe { mem::transmute(self) }

library/core/src/task/wake.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ impl RawWakerVTable {
130130
#[rustc_promotable]
131131
#[stable(feature = "futures_api", since = "1.36.0")]
132132
#[rustc_const_stable(feature = "futures_api", since = "1.36.0")]
133-
#[allow_internal_unstable(const_fn_fn_ptr_basics)]
133+
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn_fn_ptr_basics))]
134+
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn_fn_ptr_basics))]
134135
pub const fn new(
135136
clone: unsafe fn(*const ()) -> RawWaker,
136137
wake: unsafe fn(*const ()),

library/proc_macro/src/bridge/client.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,8 @@ fn run_client<A: for<'a, 's> DecodeMut<'a, 's, ()>, R: Encode<()>>(
401401
}
402402

403403
impl Client<fn(crate::TokenStream) -> crate::TokenStream> {
404-
#[allow_internal_unstable(const_fn)]
404+
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn))]
405+
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn))]
405406
pub const fn expand1(f: fn(crate::TokenStream) -> crate::TokenStream) -> Self {
406407
extern "C" fn run(
407408
bridge: Bridge<'_>,
@@ -414,7 +415,8 @@ impl Client<fn(crate::TokenStream) -> crate::TokenStream> {
414415
}
415416

416417
impl Client<fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream> {
417-
#[allow_internal_unstable(const_fn)]
418+
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn))]
419+
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn))]
418420
pub const fn expand2(
419421
f: fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream,
420422
) -> Self {
@@ -459,7 +461,8 @@ impl ProcMacro {
459461
}
460462
}
461463

462-
#[allow_internal_unstable(const_fn)]
464+
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn))]
465+
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn))]
463466
pub const fn custom_derive(
464467
trait_name: &'static str,
465468
attributes: &'static [&'static str],
@@ -468,15 +471,17 @@ impl ProcMacro {
468471
ProcMacro::CustomDerive { trait_name, attributes, client: Client::expand1(expand) }
469472
}
470473

471-
#[allow_internal_unstable(const_fn)]
474+
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn))]
475+
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn))]
472476
pub const fn attr(
473477
name: &'static str,
474478
expand: fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream,
475479
) -> Self {
476480
ProcMacro::Attr { name, client: Client::expand2(expand) }
477481
}
478482

479-
#[allow_internal_unstable(const_fn)]
483+
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn))]
484+
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn))]
480485
pub const fn bang(
481486
name: &'static str,
482487
expand: fn(crate::TokenStream) -> crate::TokenStream,

library/proc_macro/src/bridge/scoped_cell.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ impl<'a, 'b, T: LambdaL> DerefMut for RefMutL<'a, 'b, T> {
3535
pub struct ScopedCell<T: LambdaL>(Cell<<T as ApplyL<'static>>::Out>);
3636

3737
impl<T: LambdaL> ScopedCell<T> {
38-
#[allow_internal_unstable(const_fn)]
38+
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn))]
39+
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn))]
3940
pub const fn new(value: <T as ApplyL<'static>>::Out) -> Self {
4041
ScopedCell(Cell::new(value))
4142
}

library/proc_macro/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
test(no_crate_inject, attr(deny(warnings))),
1919
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
2020
)]
21+
#![cfg_attr(not(bootstrap), feature(rustc_allow_const_fn_unstable))]
2122
#![feature(nll)]
2223
#![feature(staged_api)]
2324
#![feature(const_fn)]

library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@
206206
#![needs_panic_runtime]
207207
// std may use features in a platform-specific way
208208
#![allow(unused_features)]
209+
#![cfg_attr(not(bootstrap), feature(rustc_allow_const_fn_unstable))]
209210
#![cfg_attr(test, feature(print_internals, set_stdio, update_panic_count))]
210211
#![cfg_attr(
211212
all(target_vendor = "fortanix", target_env = "sgx"),

library/std/src/net/ip.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,8 @@ impl Ipv6Addr {
10431043
/// ```
10441044
#[stable(feature = "rust1", since = "1.0.0")]
10451045
#[rustc_const_stable(feature = "const_ipv6", since = "1.32.0")]
1046-
#[allow_internal_unstable(const_fn_transmute)]
1046+
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn_transmute))]
1047+
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn_transmute))]
10471048
pub const fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> Ipv6Addr {
10481049
let addr16 = [
10491050
a.to_be(),
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(rustc_attrs, staged_api, allow_internal_unstable)]
1+
#![feature(rustc_attrs, staged_api, rustc_allow_const_fn_unstable)]
22
#![feature(const_fn_fn_ptr_basics)]
33

44
#[stable(feature = "rust1", since = "1.0.0")]
@@ -8,7 +8,7 @@ const fn error(_: fn()) {}
88

99
#[stable(feature = "rust1", since = "1.0.0")]
1010
#[rustc_const_stable(since="1.0.0", feature = "mep")]
11-
#[allow_internal_unstable(const_fn_fn_ptr_basics)]
11+
#[rustc_allow_const_fn_unstable(const_fn_fn_ptr_basics)]
1212
const fn compiles(_: fn()) {}
1313

1414
fn main() {}

src/test/ui/consts/min_const_fn/allow_const_fn_ptr.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ help: if it is not part of the public API, make this function unstably const
88
|
99
LL | #[rustc_const_unstable(feature = "...", issue = "...")]
1010
|
11-
help: otherwise `#[allow_internal_unstable]` can be used to bypass stability checks
11+
help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
1212
|
13-
LL | #[allow_internal_unstable(const_fn_fn_ptr_basics)]
13+
LL | #[rustc_allow_const_fn_unstable(const_fn_fn_ptr_basics)]
1414
|
1515

1616
error: aborting due to previous error

src/test/ui/consts/min_const_fn/allow_const_fn_ptr_run_pass.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// run-pass
2-
#![feature(allow_internal_unstable)]
2+
#![feature(rustc_allow_const_fn_unstable)]
33
#![feature(const_fn_fn_ptr_basics)]
44

55
#![feature(rustc_attrs, staged_api)]
66
#![stable(feature = "rust1", since = "1.0.0")]
77

88
#[stable(feature = "rust1", since = "1.0.0")]
99
#[rustc_const_stable(since="1.0.0", feature = "mep")]
10-
#[allow_internal_unstable(const_fn_fn_ptr_basics)]
10+
#[rustc_allow_const_fn_unstable(const_fn_fn_ptr_basics)]
1111
const fn takes_fn_ptr(_: fn()) {}
1212

1313
const FN: fn() = || ();

src/test/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ help: if it is not part of the public API, make this function unstably const
2424
|
2525
LL | #[rustc_const_unstable(feature = "...", issue = "...")]
2626
|
27-
help: otherwise `#[allow_internal_unstable]` can be used to bypass stability checks
27+
help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
2828
|
29-
LL | #[allow_internal_unstable(const_fn_floating_point_arithmetic)]
29+
LL | #[rustc_allow_const_fn_unstable(const_fn_floating_point_arithmetic)]
3030
|
3131

3232
error: `foo2_gated` is not yet stable as a const fn

src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ help: if it is not part of the public API, make this function unstably const
2424
|
2525
LL | #[rustc_const_unstable(feature = "...", issue = "...")]
2626
|
27-
help: otherwise `#[allow_internal_unstable]` can be used to bypass stability checks
27+
help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
2828
|
29-
LL | #[allow_internal_unstable(const_fn_floating_point_arithmetic)]
29+
LL | #[rustc_allow_const_fn_unstable(const_fn_floating_point_arithmetic)]
3030
|
3131

3232
error: `foo2_gated` is not yet stable as a const fn

0 commit comments

Comments
 (0)