Skip to content

const-check: stop recommending the use of rustc_allow_const_fn_unstable #141559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions compiler/rustc_const_eval/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ const_eval_unstable_in_stable_exposed =
.unstable_sugg = if the {$is_function_call2 ->
[true] caller
*[false] function
} is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
.bypass_sugg = otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
} is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`

const_eval_unstable_intrinsic = `{$name}` is not yet stable as a const intrinsic
const_eval_unstable_intrinsic_suggestion = add `#![feature({$feature})]` to the crate attributes to enable
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_const_eval/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ pub(crate) struct UnstableInStableExposed {
code = "#[rustc_const_unstable(feature = \"...\", issue = \"...\")]\n",
applicability = "has-placeholders"
)]
#[suggestion(
const_eval_bypass_sugg,
code = "#[rustc_allow_const_fn_unstable({gate})]\n",
applicability = "has-placeholders"
)]
pub attr_span: Span,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ LL | const fn bar() -> u32 { foo() }
| ^^^^^
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | const fn bar() -> u32 { foo() }
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(foo)]
LL | const fn bar() -> u32 { foo() }
|

Expand Down
21 changes: 3 additions & 18 deletions tests/ui/consts/const-unstable-intrinsic.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,9 @@ error: const function that might be (indirectly) exposed to stable cannot use `#
LL | size_of_val(&x);
| ^^^^^^^^^^^^^^^
|
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the function is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | const fn const_main() {
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(local)]
LL | const fn const_main() {
|

Expand All @@ -63,14 +58,9 @@ error: const function that might be (indirectly) exposed to stable cannot use `#
LL | min_align_of_val(&x);
| ^^^^^^^^^^^^^^^^^^^^
|
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the function is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | const fn const_main() {
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(local)]
LL | const fn const_main() {
|

Expand All @@ -88,14 +78,9 @@ error: const function that might be (indirectly) exposed to stable cannot use `#
LL | super::size_of_val(src);
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the function is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | const unsafe fn copy<T>(src: *const T, _dst: *mut T, _count: usize) {
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(local)]
LL | const unsafe fn copy<T>(src: *const T, _dst: *mut T, _count: usize) {
|

Expand Down
49 changes: 7 additions & 42 deletions tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ LL | const fn bar() -> u32 { foo() }
| ^^^^^
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | const fn bar() -> u32 { foo() }
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(foo)]
LL | const fn bar() -> u32 { foo() }
|

Expand All @@ -23,14 +18,9 @@ LL | const fn bar2() -> u32 { foo2() }
| ^^^^^^
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | const fn bar2() -> u32 { foo2() }
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(foo2)]
LL | const fn bar2() -> u32 { foo2() }
|

Expand All @@ -40,14 +30,9 @@ error: const function that might be (indirectly) exposed to stable cannot use `#
LL | let x = async { 13 };
| ^^^^^^^^^^^^
|
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the function is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | const fn bar3() -> u32 {
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(const_async_blocks)]
LL | const fn bar3() -> u32 {
|

Expand All @@ -58,14 +43,9 @@ LL | foo()
| ^^^^^
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | const fn bar3() -> u32 {
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(foo)]
LL | const fn bar3() -> u32 {
|

Expand All @@ -76,14 +56,9 @@ LL | const fn bar2_gated() -> u32 { foo2_gated() }
| ^^^^^^^^^^^^
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | const fn bar2_gated() -> u32 { foo2_gated() }
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(foo2)]
LL | const fn bar2_gated() -> u32 { foo2_gated() }
|

Expand All @@ -94,14 +69,9 @@ LL | pub(crate) const fn bar2_gated_stable_indirect() -> u32 { super::foo2_g
| ^^^^^^^^^^^^^^^^^^^
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | pub(crate) const fn bar2_gated_stable_indirect() -> u32 { super::foo2_gated() }
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(foo2)]
LL | pub(crate) const fn bar2_gated_stable_indirect() -> u32 { super::foo2_gated() }
|

Expand All @@ -112,14 +82,9 @@ LL | const fn stable_indirect() -> u32 { foo2_gated() }
| ^^^^^^^^^^^^
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | const fn stable_indirect() -> u32 { foo2_gated() }
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(foo2)]
LL | const fn stable_indirect() -> u32 { foo2_gated() }
|

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ LL | const unsafe fn bar() -> u32 { unsafe { foo() } }
| ^^^^^
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | const unsafe fn bar() -> u32 { unsafe { foo() } }
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(foo)]
LL | const unsafe fn bar() -> u32 { unsafe { foo() } }
|

Expand All @@ -23,14 +18,9 @@ LL | const unsafe fn bar2() -> u32 { unsafe { foo2() } }
| ^^^^^^
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | const unsafe fn bar2() -> u32 { unsafe { foo2() } }
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(foo2)]
LL | const unsafe fn bar2() -> u32 { unsafe { foo2() } }
|

Expand All @@ -41,14 +31,9 @@ LL | const unsafe fn bar2_gated() -> u32 { unsafe { foo2_gated() } }
| ^^^^^^^^^^^^
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | const unsafe fn bar2_gated() -> u32 { unsafe { foo2_gated() } }
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(foo2)]
LL | const unsafe fn bar2_gated() -> u32 { unsafe { foo2_gated() } }
|

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ LL | const unsafe fn bar() -> u32 { foo() }
| ^^^^^
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | const unsafe fn bar() -> u32 { foo() }
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(foo)]
LL | const unsafe fn bar() -> u32 { foo() }
|

Expand All @@ -23,14 +18,9 @@ LL | const unsafe fn bar2() -> u32 { foo2() }
| ^^^^^^
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | const unsafe fn bar2() -> u32 { foo2() }
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(foo2)]
LL | const unsafe fn bar2() -> u32 { foo2() }
|

Expand All @@ -41,14 +31,9 @@ LL | const unsafe fn bar2_gated() -> u32 { foo2_gated() }
| ^^^^^^^^^^^^
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | const unsafe fn bar2_gated() -> u32 { foo2_gated() }
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(foo2)]
LL | const unsafe fn bar2_gated() -> u32 { foo2_gated() }
|

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ LL | unstable_if_unmarked_const_fn_crate::not_stably_const();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | const fn stable_fn() {
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(rustc_private)]
LL | const fn stable_fn() {
|

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ LL | not_stably_const();
| ^^^^^^^^^^^^^^^^^^
|
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
help: if the caller is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | pub const fn expose_on_stable() {
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(rustc_private)]
LL | pub const fn expose_on_stable() {
|

Expand All @@ -22,14 +17,9 @@ error: const function that might be (indirectly) exposed to stable cannot use `#
LL | let _x = async { 15 };
| ^^^^^^^^^^^^
|
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the function is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | pub const fn expose_on_stable() {
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(const_async_blocks)]
LL | pub const fn expose_on_stable() {
|

Expand Down
7 changes: 1 addition & 6 deletions tests/ui/intrinsics/const-eval-select-stability.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ error: const function that might be (indirectly) exposed to stable cannot use `#
LL | const_eval_select((), nothing, log);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: if the function is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
help: if the function is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
LL | pub const fn hey() {
|
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
|
LL + #[rustc_allow_const_fn_unstable(const_eval_select)]
LL | pub const fn hey() {
|

Expand Down
Loading
Loading