Rollup merge of #78208 - liketechnik:issue-69399, r=oli-obk
replace `#[allow_internal_unstable]` with `#[rustc_allow_const_fn_unstable]` for `const fn`s `#[allow_internal_unstable]` is currently used to side-step feature gate and stability checks. While it was originally only meant to be used only on macros, its use was expanded to `const fn`s. This pr adds stricter checks for the usage of `#[allow_internal_unstable]` (only on macros) and introduces the `#[rustc_allow_const_fn_unstable]` attribute for usage on `const fn`s. This pr does not change any of the functionality associated with the use of `#[allow_internal_unstable]` on macros or the usage of `#[rustc_allow_const_fn_unstable]` (instead of `#[allow_internal_unstable]`) on `const fn`s (see https://github.com/rust-lang/rust/issues/69399#issuecomment-712911540). Note: The check for `#[rustc_allow_const_fn_unstable]` currently only validates that the attribute is used on a function, because I don't know how I would check if the function is a `const fn` at the place of the check. I therefore openend this as a 'draft pull request'. Closes rust-lang/rust#69399 r? @oli-obk
This commit is contained in:
commit
72e02b015e
31 changed files with 177 additions and 41 deletions
|
@ -1013,13 +1013,28 @@ pub fn allow_internal_unstable<'a>(
|
||||||
sess: &'a Session,
|
sess: &'a Session,
|
||||||
attrs: &'a [Attribute],
|
attrs: &'a [Attribute],
|
||||||
) -> Option<impl Iterator<Item = Symbol> + 'a> {
|
) -> Option<impl Iterator<Item = Symbol> + 'a> {
|
||||||
let attrs = sess.filter_by_name(attrs, sym::allow_internal_unstable);
|
allow_unstable(sess, attrs, sym::allow_internal_unstable)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn rustc_allow_const_fn_unstable<'a>(
|
||||||
|
sess: &'a Session,
|
||||||
|
attrs: &'a [Attribute],
|
||||||
|
) -> Option<impl Iterator<Item = Symbol> + 'a> {
|
||||||
|
allow_unstable(sess, attrs, sym::rustc_allow_const_fn_unstable)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn allow_unstable<'a>(
|
||||||
|
sess: &'a Session,
|
||||||
|
attrs: &'a [Attribute],
|
||||||
|
symbol: Symbol,
|
||||||
|
) -> Option<impl Iterator<Item = Symbol> + 'a> {
|
||||||
|
let attrs = sess.filter_by_name(attrs, symbol);
|
||||||
let list = attrs
|
let list = attrs
|
||||||
.filter_map(move |attr| {
|
.filter_map(move |attr| {
|
||||||
attr.meta_item_list().or_else(|| {
|
attr.meta_item_list().or_else(|| {
|
||||||
sess.diagnostic().span_err(
|
sess.diagnostic().span_err(
|
||||||
attr.span,
|
attr.span,
|
||||||
"`allow_internal_unstable` expects a list of feature names",
|
&format!("`{}` expects a list of feature names", symbol.to_ident_string()),
|
||||||
);
|
);
|
||||||
None
|
None
|
||||||
})
|
})
|
||||||
|
@ -1029,8 +1044,10 @@ pub fn allow_internal_unstable<'a>(
|
||||||
Some(list.into_iter().filter_map(move |it| {
|
Some(list.into_iter().filter_map(move |it| {
|
||||||
let name = it.ident().map(|ident| ident.name);
|
let name = it.ident().map(|ident| ident.name);
|
||||||
if name.is_none() {
|
if name.is_none() {
|
||||||
sess.diagnostic()
|
sess.diagnostic().span_err(
|
||||||
.span_err(it.span(), "`allow_internal_unstable` expects feature names");
|
it.span(),
|
||||||
|
&format!("`{}` expects feature names", symbol.to_ident_string()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
name
|
name
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -210,6 +210,11 @@ declare_features! (
|
||||||
/// it is not on path for eventual stabilization).
|
/// it is not on path for eventual stabilization).
|
||||||
(active, no_niche, "1.42.0", None, None),
|
(active, no_niche, "1.42.0", None, None),
|
||||||
|
|
||||||
|
/// Allows using `#[rustc_allow_const_fn_unstable]`.
|
||||||
|
/// This is an attribute on `const fn` for the same
|
||||||
|
/// purpose as `#[allow_internal_unstable]`.
|
||||||
|
(active, rustc_allow_const_fn_unstable, "1.49.0", Some(69399), None),
|
||||||
|
|
||||||
// no-tracking-issue-end
|
// no-tracking-issue-end
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
|
@ -379,6 +379,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
|
||||||
allow_internal_unstable, AssumedUsed, template!(Word, List: "feat1, feat2, ..."),
|
allow_internal_unstable, AssumedUsed, template!(Word, List: "feat1, feat2, ..."),
|
||||||
"allow_internal_unstable side-steps feature gating and stability checks",
|
"allow_internal_unstable side-steps feature gating and stability checks",
|
||||||
),
|
),
|
||||||
|
gated!(
|
||||||
|
rustc_allow_const_fn_unstable, AssumedUsed, template!(Word, List: "feat1, feat2, ..."),
|
||||||
|
"rustc_allow_const_fn_unstable side-steps feature gating and stability checks"
|
||||||
|
),
|
||||||
gated!(
|
gated!(
|
||||||
allow_internal_unsafe, Normal, template!(Word),
|
allow_internal_unsafe, Normal, template!(Word),
|
||||||
"allow_internal_unsafe side-steps the unsafe_code lint",
|
"allow_internal_unsafe side-steps the unsafe_code lint",
|
||||||
|
|
|
@ -79,9 +79,13 @@ pub fn is_lang_panic_fn(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
|
||||||
|| Some(def_id) == tcx.lang_items().begin_panic_fn()
|
|| Some(def_id) == tcx.lang_items().begin_panic_fn()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn allow_internal_unstable(tcx: TyCtxt<'tcx>, def_id: DefId, feature_gate: Symbol) -> bool {
|
pub fn rustc_allow_const_fn_unstable(
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
def_id: DefId,
|
||||||
|
feature_gate: Symbol,
|
||||||
|
) -> bool {
|
||||||
let attrs = tcx.get_attrs(def_id);
|
let attrs = tcx.get_attrs(def_id);
|
||||||
attr::allow_internal_unstable(&tcx.sess, attrs)
|
attr::rustc_allow_const_fn_unstable(&tcx.sess, attrs)
|
||||||
.map_or(false, |mut features| features.any(|name| name == feature_gate))
|
.map_or(false, |mut features| features.any(|name| name == feature_gate))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -292,7 +292,11 @@ impl Validator<'mir, 'tcx> {
|
||||||
|
|
||||||
Status::Unstable(gate) if self.tcx.features().enabled(gate) => {
|
Status::Unstable(gate) if self.tcx.features().enabled(gate) => {
|
||||||
let unstable_in_stable = self.ccx.is_const_stable_const_fn()
|
let unstable_in_stable = self.ccx.is_const_stable_const_fn()
|
||||||
&& !super::allow_internal_unstable(self.tcx, self.def_id().to_def_id(), gate);
|
&& !super::rustc_allow_const_fn_unstable(
|
||||||
|
self.tcx,
|
||||||
|
self.def_id().to_def_id(),
|
||||||
|
gate,
|
||||||
|
);
|
||||||
if unstable_in_stable {
|
if unstable_in_stable {
|
||||||
emit_unstable_in_stable_error(self.ccx, span, gate);
|
emit_unstable_in_stable_error(self.ccx, span, gate);
|
||||||
}
|
}
|
||||||
|
@ -807,7 +811,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calling an unstable function *always* requires that the corresponding gate
|
// Calling an unstable function *always* requires that the corresponding gate
|
||||||
// be enabled, even if the function has `#[allow_internal_unstable(the_gate)]`.
|
// be enabled, even if the function has `#[rustc_allow_const_fn_unstable(the_gate)]`.
|
||||||
if !tcx.features().declared_lib_features.iter().any(|&(sym, _)| sym == gate) {
|
if !tcx.features().declared_lib_features.iter().any(|&(sym, _)| sym == gate) {
|
||||||
self.check_op(ops::FnCallUnstable(callee, Some(gate)));
|
self.check_op(ops::FnCallUnstable(callee, Some(gate)));
|
||||||
return;
|
return;
|
||||||
|
@ -821,7 +825,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
|
||||||
|
|
||||||
// Otherwise, we are something const-stable calling a const-unstable fn.
|
// Otherwise, we are something const-stable calling a const-unstable fn.
|
||||||
|
|
||||||
if super::allow_internal_unstable(tcx, caller, gate) {
|
if super::rustc_allow_const_fn_unstable(tcx, caller, gate) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -967,8 +971,8 @@ fn emit_unstable_in_stable_error(ccx: &ConstCx<'_, '_>, span: Span, gate: Symbol
|
||||||
)
|
)
|
||||||
.span_suggestion(
|
.span_suggestion(
|
||||||
attr_span,
|
attr_span,
|
||||||
"otherwise `#[allow_internal_unstable]` can be used to bypass stability checks",
|
"otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks",
|
||||||
format!("#[allow_internal_unstable({})]\n", gate),
|
format!("#[rustc_allow_const_fn_unstable({})]\n", gate),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
|
|
|
@ -85,6 +85,10 @@ impl CheckAttrVisitor<'tcx> {
|
||||||
self.check_export_name(&attr, span, target)
|
self.check_export_name(&attr, span, target)
|
||||||
} else if self.tcx.sess.check_name(attr, sym::rustc_args_required_const) {
|
} else if self.tcx.sess.check_name(attr, sym::rustc_args_required_const) {
|
||||||
self.check_rustc_args_required_const(&attr, span, target, item)
|
self.check_rustc_args_required_const(&attr, span, target, item)
|
||||||
|
} else if self.tcx.sess.check_name(attr, sym::allow_internal_unstable) {
|
||||||
|
self.check_allow_internal_unstable(&attr, span, target, &attrs)
|
||||||
|
} else if self.tcx.sess.check_name(attr, sym::rustc_allow_const_fn_unstable) {
|
||||||
|
self.check_rustc_allow_const_fn_unstable(hir_id, &attr, span, target)
|
||||||
} else {
|
} else {
|
||||||
// lint-only checks
|
// lint-only checks
|
||||||
if self.tcx.sess.check_name(attr, sym::cold) {
|
if self.tcx.sess.check_name(attr, sym::cold) {
|
||||||
|
@ -719,6 +723,55 @@ impl CheckAttrVisitor<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Outputs an error for `#[allow_internal_unstable]` which can only be applied to macros.
|
||||||
|
/// (Allows proc_macro functions)
|
||||||
|
fn check_allow_internal_unstable(
|
||||||
|
&self,
|
||||||
|
attr: &Attribute,
|
||||||
|
span: &Span,
|
||||||
|
target: Target,
|
||||||
|
attrs: &[Attribute],
|
||||||
|
) -> bool {
|
||||||
|
debug!("Checking target: {:?}", target);
|
||||||
|
if target == Target::Fn {
|
||||||
|
for attr in attrs {
|
||||||
|
if self.tcx.sess.is_proc_macro_attr(attr) {
|
||||||
|
debug!("Is proc macro attr");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debug!("Is not proc macro attr");
|
||||||
|
}
|
||||||
|
self.tcx
|
||||||
|
.sess
|
||||||
|
.struct_span_err(attr.span, "attribute should be applied to a macro")
|
||||||
|
.span_label(*span, "not a macro")
|
||||||
|
.emit();
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Outputs an error for `#[allow_internal_unstable]` which can only be applied to macros.
|
||||||
|
/// (Allows proc_macro functions)
|
||||||
|
fn check_rustc_allow_const_fn_unstable(
|
||||||
|
&self,
|
||||||
|
hir_id: HirId,
|
||||||
|
attr: &Attribute,
|
||||||
|
span: &Span,
|
||||||
|
target: Target,
|
||||||
|
) -> bool {
|
||||||
|
if let Target::Fn | Target::Method(_) = target {
|
||||||
|
if self.tcx.is_const_fn_raw(self.tcx.hir().local_def_id(hir_id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.tcx
|
||||||
|
.sess
|
||||||
|
.struct_span_err(attr.span, "attribute should be applied to `const fn`")
|
||||||
|
.span_label(*span, "not a `const fn`")
|
||||||
|
.emit();
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
||||||
|
|
|
@ -87,7 +87,7 @@ impl<'tcx> CheckConstVisitor<'tcx> {
|
||||||
|
|
||||||
let is_feature_allowed = |feature_gate| {
|
let is_feature_allowed = |feature_gate| {
|
||||||
// All features require that the corresponding gate be enabled,
|
// All features require that the corresponding gate be enabled,
|
||||||
// even if the function has `#[allow_internal_unstable(the_gate)]`.
|
// even if the function has `#[rustc_allow_const_fn_unstable(the_gate)]`.
|
||||||
if !tcx.features().enabled(feature_gate) {
|
if !tcx.features().enabled(feature_gate) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -105,8 +105,8 @@ impl<'tcx> CheckConstVisitor<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// However, we cannot allow stable `const fn`s to use unstable features without an explicit
|
// However, we cannot allow stable `const fn`s to use unstable features without an explicit
|
||||||
// opt-in via `allow_internal_unstable`.
|
// opt-in via `rustc_allow_const_fn_unstable`.
|
||||||
attr::allow_internal_unstable(&tcx.sess, &tcx.get_attrs(def_id))
|
attr::rustc_allow_const_fn_unstable(&tcx.sess, &tcx.get_attrs(def_id))
|
||||||
.map_or(false, |mut features| features.any(|name| name == feature_gate))
|
.map_or(false, |mut features| features.any(|name| name == feature_gate))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -894,6 +894,7 @@ symbols! {
|
||||||
rustc,
|
rustc,
|
||||||
rustc_allocator,
|
rustc_allocator,
|
||||||
rustc_allocator_nounwind,
|
rustc_allocator_nounwind,
|
||||||
|
rustc_allow_const_fn_unstable,
|
||||||
rustc_args_required_const,
|
rustc_args_required_const,
|
||||||
rustc_attrs,
|
rustc_attrs,
|
||||||
rustc_builtin_macro,
|
rustc_builtin_macro,
|
||||||
|
|
|
@ -72,6 +72,7 @@
|
||||||
#![allow(explicit_outlives_requirements)]
|
#![allow(explicit_outlives_requirements)]
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
#![deny(unsafe_op_in_unsafe_fn)]
|
#![deny(unsafe_op_in_unsafe_fn)]
|
||||||
|
#![cfg_attr(not(bootstrap), feature(rustc_allow_const_fn_unstable))]
|
||||||
#![cfg_attr(not(test), feature(generator_trait))]
|
#![cfg_attr(not(test), feature(generator_trait))]
|
||||||
#![cfg_attr(test, feature(test))]
|
#![cfg_attr(test, feature(test))]
|
||||||
#![cfg_attr(test, feature(new_uninit))]
|
#![cfg_attr(test, feature(new_uninit))]
|
||||||
|
|
|
@ -150,7 +150,8 @@ impl<T> RawVec<T, Global> {
|
||||||
impl<T, A: AllocRef> RawVec<T, A> {
|
impl<T, A: AllocRef> RawVec<T, A> {
|
||||||
/// Like `new`, but parameterized over the choice of allocator for
|
/// Like `new`, but parameterized over the choice of allocator for
|
||||||
/// the returned `RawVec`.
|
/// the returned `RawVec`.
|
||||||
#[allow_internal_unstable(const_fn)]
|
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn))]
|
||||||
|
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn))]
|
||||||
pub const fn new_in(alloc: A) -> Self {
|
pub const fn new_in(alloc: A) -> Self {
|
||||||
// `cap: 0` means "unallocated". zero-sized types are ignored.
|
// `cap: 0` means "unallocated". zero-sized types are ignored.
|
||||||
Self { ptr: Unique::dangling(), cap: 0, alloc }
|
Self { ptr: Unique::dangling(), cap: 0, alloc }
|
||||||
|
|
|
@ -63,6 +63,7 @@
|
||||||
#![warn(missing_debug_implementations)]
|
#![warn(missing_debug_implementations)]
|
||||||
#![allow(explicit_outlives_requirements)]
|
#![allow(explicit_outlives_requirements)]
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
#![cfg_attr(not(bootstrap), feature(rustc_allow_const_fn_unstable))]
|
||||||
#![feature(allow_internal_unstable)]
|
#![feature(allow_internal_unstable)]
|
||||||
#![feature(arbitrary_self_types)]
|
#![feature(arbitrary_self_types)]
|
||||||
#![feature(asm)]
|
#![feature(asm)]
|
||||||
|
|
|
@ -2045,7 +2045,8 @@ assert_eq!(
|
||||||
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
|
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
|
||||||
// SAFETY: const sound because integers are plain old datatypes so we can always
|
// SAFETY: const sound because integers are plain old datatypes so we can always
|
||||||
// transmute them to arrays of bytes
|
// transmute them to arrays of bytes
|
||||||
#[allow_internal_unstable(const_fn_transmute)]
|
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn_transmute))]
|
||||||
|
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn_transmute))]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
|
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
|
||||||
// SAFETY: integers are plain old datatypes so we can always transmute them to
|
// 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),
|
||||||
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
|
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
|
||||||
// SAFETY: const sound because integers are plain old datatypes so we can always
|
// SAFETY: const sound because integers are plain old datatypes so we can always
|
||||||
// transmute to them
|
// transmute to them
|
||||||
#[allow_internal_unstable(const_fn_transmute)]
|
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn_transmute))]
|
||||||
|
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn_transmute))]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
|
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
|
||||||
// SAFETY: integers are plain old datatypes so we can always transmute to them
|
// SAFETY: integers are plain old datatypes so we can always transmute to them
|
||||||
|
|
|
@ -1803,7 +1803,8 @@ assert_eq!(
|
||||||
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
|
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
|
||||||
// SAFETY: const sound because integers are plain old datatypes so we can always
|
// SAFETY: const sound because integers are plain old datatypes so we can always
|
||||||
// transmute them to arrays of bytes
|
// transmute them to arrays of bytes
|
||||||
#[allow_internal_unstable(const_fn_transmute)]
|
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn_transmute))]
|
||||||
|
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn_transmute))]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
|
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
|
||||||
// SAFETY: integers are plain old datatypes so we can always transmute them to
|
// 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),
|
||||||
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
|
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
|
||||||
// SAFETY: const sound because integers are plain old datatypes so we can always
|
// SAFETY: const sound because integers are plain old datatypes so we can always
|
||||||
// transmute to them
|
// transmute to them
|
||||||
#[allow_internal_unstable(const_fn_transmute)]
|
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn_transmute))]
|
||||||
|
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn_transmute))]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
|
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
|
||||||
// SAFETY: integers are plain old datatypes so we can always transmute to them
|
// SAFETY: integers are plain old datatypes so we can always transmute to them
|
||||||
|
|
|
@ -88,7 +88,8 @@ impl<T> [T] {
|
||||||
#[rustc_const_stable(feature = "const_slice_len", since = "1.32.0")]
|
#[rustc_const_stable(feature = "const_slice_len", since = "1.32.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
// SAFETY: const sound because we transmute out the length field as a usize (which it must be)
|
// SAFETY: const sound because we transmute out the length field as a usize (which it must be)
|
||||||
#[allow_internal_unstable(const_fn_union)]
|
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn_union))]
|
||||||
|
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn_union))]
|
||||||
pub const fn len(&self) -> usize {
|
pub const fn len(&self) -> usize {
|
||||||
// SAFETY: this is safe because `&[T]` and `FatPtr<T>` have the same layout.
|
// SAFETY: this is safe because `&[T]` and `FatPtr<T>` have the same layout.
|
||||||
// Only `std` can make this guarantee.
|
// Only `std` can make this guarantee.
|
||||||
|
|
|
@ -157,7 +157,8 @@ pub fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error> {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_const_unstable(feature = "const_str_from_utf8_unchecked", issue = "75196")]
|
#[rustc_const_unstable(feature = "const_str_from_utf8_unchecked", issue = "75196")]
|
||||||
#[allow_internal_unstable(const_fn_transmute)]
|
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn_transmute))]
|
||||||
|
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn_transmute))]
|
||||||
pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str {
|
pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str {
|
||||||
// SAFETY: the caller must guarantee that the bytes `v` are valid UTF-8.
|
// SAFETY: the caller must guarantee that the bytes `v` are valid UTF-8.
|
||||||
// Also relies on `&str` and `&[u8]` having the same layout.
|
// Also relies on `&str` and `&[u8]` having the same layout.
|
||||||
|
|
|
@ -219,7 +219,8 @@ impl str {
|
||||||
#[rustc_const_stable(feature = "str_as_bytes", since = "1.32.0")]
|
#[rustc_const_stable(feature = "str_as_bytes", since = "1.32.0")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[allow(unused_attributes)]
|
#[allow(unused_attributes)]
|
||||||
#[allow_internal_unstable(const_fn_transmute)]
|
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn_transmute))]
|
||||||
|
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn_transmute))]
|
||||||
pub const fn as_bytes(&self) -> &[u8] {
|
pub const fn as_bytes(&self) -> &[u8] {
|
||||||
// SAFETY: const sound because we transmute two types with the same layout
|
// SAFETY: const sound because we transmute two types with the same layout
|
||||||
unsafe { mem::transmute(self) }
|
unsafe { mem::transmute(self) }
|
||||||
|
|
|
@ -130,7 +130,8 @@ impl RawWakerVTable {
|
||||||
#[rustc_promotable]
|
#[rustc_promotable]
|
||||||
#[stable(feature = "futures_api", since = "1.36.0")]
|
#[stable(feature = "futures_api", since = "1.36.0")]
|
||||||
#[rustc_const_stable(feature = "futures_api", since = "1.36.0")]
|
#[rustc_const_stable(feature = "futures_api", since = "1.36.0")]
|
||||||
#[allow_internal_unstable(const_fn_fn_ptr_basics)]
|
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn_fn_ptr_basics))]
|
||||||
|
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn_fn_ptr_basics))]
|
||||||
pub const fn new(
|
pub const fn new(
|
||||||
clone: unsafe fn(*const ()) -> RawWaker,
|
clone: unsafe fn(*const ()) -> RawWaker,
|
||||||
wake: unsafe fn(*const ()),
|
wake: unsafe fn(*const ()),
|
||||||
|
|
|
@ -401,7 +401,8 @@ fn run_client<A: for<'a, 's> DecodeMut<'a, 's, ()>, R: Encode<()>>(
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Client<fn(crate::TokenStream) -> crate::TokenStream> {
|
impl Client<fn(crate::TokenStream) -> crate::TokenStream> {
|
||||||
#[allow_internal_unstable(const_fn)]
|
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn))]
|
||||||
|
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn))]
|
||||||
pub const fn expand1(f: fn(crate::TokenStream) -> crate::TokenStream) -> Self {
|
pub const fn expand1(f: fn(crate::TokenStream) -> crate::TokenStream) -> Self {
|
||||||
extern "C" fn run(
|
extern "C" fn run(
|
||||||
bridge: Bridge<'_>,
|
bridge: Bridge<'_>,
|
||||||
|
@ -414,7 +415,8 @@ impl Client<fn(crate::TokenStream) -> crate::TokenStream> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Client<fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream> {
|
impl Client<fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream> {
|
||||||
#[allow_internal_unstable(const_fn)]
|
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn))]
|
||||||
|
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn))]
|
||||||
pub const fn expand2(
|
pub const fn expand2(
|
||||||
f: fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream,
|
f: fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -459,7 +461,8 @@ impl ProcMacro {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow_internal_unstable(const_fn)]
|
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn))]
|
||||||
|
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn))]
|
||||||
pub const fn custom_derive(
|
pub const fn custom_derive(
|
||||||
trait_name: &'static str,
|
trait_name: &'static str,
|
||||||
attributes: &'static [&'static str],
|
attributes: &'static [&'static str],
|
||||||
|
@ -468,7 +471,8 @@ impl ProcMacro {
|
||||||
ProcMacro::CustomDerive { trait_name, attributes, client: Client::expand1(expand) }
|
ProcMacro::CustomDerive { trait_name, attributes, client: Client::expand1(expand) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow_internal_unstable(const_fn)]
|
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn))]
|
||||||
|
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn))]
|
||||||
pub const fn attr(
|
pub const fn attr(
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
expand: fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream,
|
expand: fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream,
|
||||||
|
@ -476,7 +480,8 @@ impl ProcMacro {
|
||||||
ProcMacro::Attr { name, client: Client::expand2(expand) }
|
ProcMacro::Attr { name, client: Client::expand2(expand) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow_internal_unstable(const_fn)]
|
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn))]
|
||||||
|
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn))]
|
||||||
pub const fn bang(
|
pub const fn bang(
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
expand: fn(crate::TokenStream) -> crate::TokenStream,
|
expand: fn(crate::TokenStream) -> crate::TokenStream,
|
||||||
|
|
|
@ -35,7 +35,8 @@ impl<'a, 'b, T: LambdaL> DerefMut for RefMutL<'a, 'b, T> {
|
||||||
pub struct ScopedCell<T: LambdaL>(Cell<<T as ApplyL<'static>>::Out>);
|
pub struct ScopedCell<T: LambdaL>(Cell<<T as ApplyL<'static>>::Out>);
|
||||||
|
|
||||||
impl<T: LambdaL> ScopedCell<T> {
|
impl<T: LambdaL> ScopedCell<T> {
|
||||||
#[allow_internal_unstable(const_fn)]
|
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn))]
|
||||||
|
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn))]
|
||||||
pub const fn new(value: <T as ApplyL<'static>>::Out) -> Self {
|
pub const fn new(value: <T as ApplyL<'static>>::Out) -> Self {
|
||||||
ScopedCell(Cell::new(value))
|
ScopedCell(Cell::new(value))
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
test(no_crate_inject, attr(deny(warnings))),
|
test(no_crate_inject, attr(deny(warnings))),
|
||||||
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
|
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
|
||||||
)]
|
)]
|
||||||
|
#![cfg_attr(not(bootstrap), feature(rustc_allow_const_fn_unstable))]
|
||||||
#![feature(nll)]
|
#![feature(nll)]
|
||||||
#![feature(staged_api)]
|
#![feature(staged_api)]
|
||||||
#![feature(const_fn)]
|
#![feature(const_fn)]
|
||||||
|
|
|
@ -206,6 +206,7 @@
|
||||||
#![needs_panic_runtime]
|
#![needs_panic_runtime]
|
||||||
// std may use features in a platform-specific way
|
// std may use features in a platform-specific way
|
||||||
#![allow(unused_features)]
|
#![allow(unused_features)]
|
||||||
|
#![cfg_attr(not(bootstrap), feature(rustc_allow_const_fn_unstable))]
|
||||||
#![cfg_attr(test, feature(print_internals, set_stdio, update_panic_count))]
|
#![cfg_attr(test, feature(print_internals, set_stdio, update_panic_count))]
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
all(target_vendor = "fortanix", target_env = "sgx"),
|
all(target_vendor = "fortanix", target_env = "sgx"),
|
||||||
|
|
|
@ -1043,7 +1043,8 @@ impl Ipv6Addr {
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_const_stable(feature = "const_ipv6", since = "1.32.0")]
|
#[rustc_const_stable(feature = "const_ipv6", since = "1.32.0")]
|
||||||
#[allow_internal_unstable(const_fn_transmute)]
|
#[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn_transmute))]
|
||||||
|
#[cfg_attr(bootstrap, allow_internal_unstable(const_fn_transmute))]
|
||||||
pub const fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> Ipv6Addr {
|
pub const fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> Ipv6Addr {
|
||||||
let addr16 = [
|
let addr16 = [
|
||||||
a.to_be(),
|
a.to_be(),
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![feature(rustc_attrs, staged_api, allow_internal_unstable)]
|
#![feature(rustc_attrs, staged_api, rustc_allow_const_fn_unstable)]
|
||||||
#![feature(const_fn_fn_ptr_basics)]
|
#![feature(const_fn_fn_ptr_basics)]
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
@ -8,7 +8,7 @@ const fn error(_: fn()) {}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_const_stable(since="1.0.0", feature = "mep")]
|
#[rustc_const_stable(since="1.0.0", feature = "mep")]
|
||||||
#[allow_internal_unstable(const_fn_fn_ptr_basics)]
|
#[rustc_allow_const_fn_unstable(const_fn_fn_ptr_basics)]
|
||||||
const fn compiles(_: fn()) {}
|
const fn compiles(_: fn()) {}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -8,9 +8,9 @@ help: if it is not part of the public API, make this function unstably const
|
||||||
|
|
|
|
||||||
LL | #[rustc_const_unstable(feature = "...", issue = "...")]
|
LL | #[rustc_const_unstable(feature = "...", issue = "...")]
|
||||||
|
|
|
|
||||||
help: otherwise `#[allow_internal_unstable]` can be used to bypass stability checks
|
help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
|
||||||
|
|
|
|
||||||
LL | #[allow_internal_unstable(const_fn_fn_ptr_basics)]
|
LL | #[rustc_allow_const_fn_unstable(const_fn_fn_ptr_basics)]
|
||||||
|
|
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// run-pass
|
// run-pass
|
||||||
#![feature(allow_internal_unstable)]
|
#![feature(rustc_allow_const_fn_unstable)]
|
||||||
#![feature(const_fn_fn_ptr_basics)]
|
#![feature(const_fn_fn_ptr_basics)]
|
||||||
|
|
||||||
#![feature(rustc_attrs, staged_api)]
|
#![feature(rustc_attrs, staged_api)]
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_const_stable(since="1.0.0", feature = "mep")]
|
#[rustc_const_stable(since="1.0.0", feature = "mep")]
|
||||||
#[allow_internal_unstable(const_fn_fn_ptr_basics)]
|
#[rustc_allow_const_fn_unstable(const_fn_fn_ptr_basics)]
|
||||||
const fn takes_fn_ptr(_: fn()) {}
|
const fn takes_fn_ptr(_: fn()) {}
|
||||||
|
|
||||||
const FN: fn() = || ();
|
const FN: fn() = || ();
|
||||||
|
|
|
@ -24,9 +24,9 @@ help: if it is not part of the public API, make this function unstably const
|
||||||
|
|
|
|
||||||
LL | #[rustc_const_unstable(feature = "...", issue = "...")]
|
LL | #[rustc_const_unstable(feature = "...", issue = "...")]
|
||||||
|
|
|
|
||||||
help: otherwise `#[allow_internal_unstable]` can be used to bypass stability checks
|
help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
|
||||||
|
|
|
|
||||||
LL | #[allow_internal_unstable(const_fn_floating_point_arithmetic)]
|
LL | #[rustc_allow_const_fn_unstable(const_fn_floating_point_arithmetic)]
|
||||||
|
|
|
|
||||||
|
|
||||||
error: `foo2_gated` is not yet stable as a const fn
|
error: `foo2_gated` is not yet stable as a const fn
|
||||||
|
|
|
@ -24,9 +24,9 @@ help: if it is not part of the public API, make this function unstably const
|
||||||
|
|
|
|
||||||
LL | #[rustc_const_unstable(feature = "...", issue = "...")]
|
LL | #[rustc_const_unstable(feature = "...", issue = "...")]
|
||||||
|
|
|
|
||||||
help: otherwise `#[allow_internal_unstable]` can be used to bypass stability checks
|
help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
|
||||||
|
|
|
|
||||||
LL | #[allow_internal_unstable(const_fn_floating_point_arithmetic)]
|
LL | #[rustc_allow_const_fn_unstable(const_fn_floating_point_arithmetic)]
|
||||||
|
|
|
|
||||||
|
|
||||||
error: `foo2_gated` is not yet stable as a const fn
|
error: `foo2_gated` is not yet stable as a const fn
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// this needs a different test since this is done after expansion
|
// this needs a different test since this is done after expansion
|
||||||
|
|
||||||
#[allow_internal_unstable()] //~ ERROR allow_internal_unstable side-steps
|
#[allow_internal_unstable()] //~ ERROR allow_internal_unstable side-steps
|
||||||
|
//~| ERROR attribute should
|
||||||
struct S;
|
struct S;
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -6,6 +6,15 @@ LL | #[allow_internal_unstable()]
|
||||||
|
|
|
|
||||||
= help: add `#![feature(allow_internal_unstable)]` to the crate attributes to enable
|
= help: add `#![feature(allow_internal_unstable)]` to the crate attributes to enable
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: attribute should be applied to a macro
|
||||||
|
--> $DIR/feature-gate-allow-internal-unstable-struct.rs:4:1
|
||||||
|
|
|
||||||
|
LL | #[allow_internal_unstable()]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
LL |
|
||||||
|
LL | struct S;
|
||||||
|
| --------- not a macro
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0658`.
|
For more information about this error, try `rustc --explain E0658`.
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#![allow(unused_macros)]
|
||||||
|
|
||||||
|
#[rustc_allow_const_fn_unstable()] //~ ERROR rustc_allow_const_fn_unstable side-steps
|
||||||
|
const fn foo() { }
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,12 @@
|
||||||
|
error[E0658]: rustc_allow_const_fn_unstable side-steps feature gating and stability checks
|
||||||
|
--> $DIR/feature-gate-rustc-allow-const-fn-unstable.rs:3:1
|
||||||
|
|
|
||||||
|
LL | #[rustc_allow_const_fn_unstable()]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: see issue #69399 <https://github.com/rust-lang/rust/issues/69399> for more information
|
||||||
|
= help: add `#![feature(rustc_allow_const_fn_unstable)]` to the crate attributes to enable
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0658`.
|
Loading…
Add table
Add a link
Reference in a new issue