Skip to content

Commit 5a8cb6f

Browse files
authored
Rollup merge of #141559 - RalfJung:less-rustc_allow_const_fn_unstable, r=compiler-errors
const-check: stop recommending the use of rustc_allow_const_fn_unstable I have seen way too many people see the compiler suggest this attribute and then just apply it without a second thought. This is bad. So let's just stop recommending it; for the rare case where someone needs it, they'll eventually ask us and that way we can be sure that it is truly needed. The dev-guide still also explains `rustc_allow_const_fn_unstable`. Cc ``@rust-lang/wg-const-eval``
2 parents 905b46a + cf9ac0e commit 5a8cb6f

11 files changed

+41
-247
lines changed

compiler/rustc_const_eval/messages.ftl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,7 @@ const_eval_unstable_in_stable_exposed =
424424
.unstable_sugg = if the {$is_function_call2 ->
425425
[true] caller
426426
*[false] function
427-
} is not (yet) meant to be exposed to stable, add `#[rustc_const_unstable]` (this is what you probably want to do)
428-
.bypass_sugg = otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
427+
} is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
429428
430429
const_eval_unstable_intrinsic = `{$name}` is not yet stable as a const intrinsic
431430
const_eval_unstable_intrinsic_suggestion = add `#![feature({$feature})]` to the crate attributes to enable

compiler/rustc_const_eval/src/errors.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ pub(crate) struct UnstableInStableExposed {
5858
code = "#[rustc_const_unstable(feature = \"...\", issue = \"...\")]\n",
5959
applicability = "has-placeholders"
6060
)]
61-
#[suggestion(
62-
const_eval_bypass_sugg,
63-
code = "#[rustc_allow_const_fn_unstable({gate})]\n",
64-
applicability = "has-placeholders"
65-
)]
6661
pub attr_span: Span,
6762
}
6863

tests/ui/consts/const-eval/dont_promote_unstable_const_fn.stderr

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@ LL | const fn bar() -> u32 { foo() }
55
| ^^^^^
66
|
77
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
8-
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)
8+
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
99
|
1010
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
11-
LL | const fn bar() -> u32 { foo() }
12-
|
13-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
14-
|
15-
LL + #[rustc_allow_const_fn_unstable(foo)]
1611
LL | const fn bar() -> u32 { foo() }
1712
|
1813

tests/ui/consts/const-unstable-intrinsic.stderr

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,9 @@ error: const function that might be (indirectly) exposed to stable cannot use `#
4646
LL | size_of_val(&x);
4747
| ^^^^^^^^^^^^^^^
4848
|
49-
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)
49+
help: if the function is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
5050
|
5151
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
52-
LL | const fn const_main() {
53-
|
54-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
55-
|
56-
LL + #[rustc_allow_const_fn_unstable(local)]
5752
LL | const fn const_main() {
5853
|
5954

@@ -63,14 +58,9 @@ error: const function that might be (indirectly) exposed to stable cannot use `#
6358
LL | min_align_of_val(&x);
6459
| ^^^^^^^^^^^^^^^^^^^^
6560
|
66-
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)
61+
help: if the function is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
6762
|
6863
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
69-
LL | const fn const_main() {
70-
|
71-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
72-
|
73-
LL + #[rustc_allow_const_fn_unstable(local)]
7464
LL | const fn const_main() {
7565
|
7666

@@ -88,14 +78,9 @@ error: const function that might be (indirectly) exposed to stable cannot use `#
8878
LL | super::size_of_val(src);
8979
| ^^^^^^^^^^^^^^^^^^^^^^^
9080
|
91-
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)
81+
help: if the function is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
9282
|
9383
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
94-
LL | const unsafe fn copy<T>(src: *const T, _dst: *mut T, _count: usize) {
95-
|
96-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
97-
|
98-
LL + #[rustc_allow_const_fn_unstable(local)]
9984
LL | const unsafe fn copy<T>(src: *const T, _dst: *mut T, _count: usize) {
10085
|
10186

tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@ LL | const fn bar() -> u32 { foo() }
55
| ^^^^^
66
|
77
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
8-
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)
8+
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
99
|
1010
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
11-
LL | const fn bar() -> u32 { foo() }
12-
|
13-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
14-
|
15-
LL + #[rustc_allow_const_fn_unstable(foo)]
1611
LL | const fn bar() -> u32 { foo() }
1712
|
1813

@@ -23,14 +18,9 @@ LL | const fn bar2() -> u32 { foo2() }
2318
| ^^^^^^
2419
|
2520
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
26-
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)
21+
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
2722
|
2823
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
29-
LL | const fn bar2() -> u32 { foo2() }
30-
|
31-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
32-
|
33-
LL + #[rustc_allow_const_fn_unstable(foo2)]
3424
LL | const fn bar2() -> u32 { foo2() }
3525
|
3626

@@ -40,14 +30,9 @@ error: const function that might be (indirectly) exposed to stable cannot use `#
4030
LL | let x = async { 13 };
4131
| ^^^^^^^^^^^^
4232
|
43-
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)
33+
help: if the function is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
4434
|
4535
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
46-
LL | const fn bar3() -> u32 {
47-
|
48-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
49-
|
50-
LL + #[rustc_allow_const_fn_unstable(const_async_blocks)]
5136
LL | const fn bar3() -> u32 {
5237
|
5338

@@ -58,14 +43,9 @@ LL | foo()
5843
| ^^^^^
5944
|
6045
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
61-
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)
46+
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
6247
|
6348
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
64-
LL | const fn bar3() -> u32 {
65-
|
66-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
67-
|
68-
LL + #[rustc_allow_const_fn_unstable(foo)]
6949
LL | const fn bar3() -> u32 {
7050
|
7151

@@ -76,14 +56,9 @@ LL | const fn bar2_gated() -> u32 { foo2_gated() }
7656
| ^^^^^^^^^^^^
7757
|
7858
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
79-
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)
59+
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
8060
|
8161
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
82-
LL | const fn bar2_gated() -> u32 { foo2_gated() }
83-
|
84-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
85-
|
86-
LL + #[rustc_allow_const_fn_unstable(foo2)]
8762
LL | const fn bar2_gated() -> u32 { foo2_gated() }
8863
|
8964

@@ -94,14 +69,9 @@ LL | pub(crate) const fn bar2_gated_stable_indirect() -> u32 { super::foo2_g
9469
| ^^^^^^^^^^^^^^^^^^^
9570
|
9671
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
97-
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)
72+
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
9873
|
9974
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
100-
LL | pub(crate) const fn bar2_gated_stable_indirect() -> u32 { super::foo2_gated() }
101-
|
102-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
103-
|
104-
LL + #[rustc_allow_const_fn_unstable(foo2)]
10575
LL | pub(crate) const fn bar2_gated_stable_indirect() -> u32 { super::foo2_gated() }
10676
|
10777

@@ -112,14 +82,9 @@ LL | const fn stable_indirect() -> u32 { foo2_gated() }
11282
| ^^^^^^^^^^^^
11383
|
11484
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
115-
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)
85+
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
11686
|
11787
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
118-
LL | const fn stable_indirect() -> u32 { foo2_gated() }
119-
|
120-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
121-
|
122-
LL + #[rustc_allow_const_fn_unstable(foo2)]
12388
LL | const fn stable_indirect() -> u32 { foo2_gated() }
12489
|
12590

tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@ LL | const unsafe fn bar() -> u32 { unsafe { foo() } }
55
| ^^^^^
66
|
77
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
8-
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)
8+
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
99
|
1010
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
11-
LL | const unsafe fn bar() -> u32 { unsafe { foo() } }
12-
|
13-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
14-
|
15-
LL + #[rustc_allow_const_fn_unstable(foo)]
1611
LL | const unsafe fn bar() -> u32 { unsafe { foo() } }
1712
|
1813

@@ -23,14 +18,9 @@ LL | const unsafe fn bar2() -> u32 { unsafe { foo2() } }
2318
| ^^^^^^
2419
|
2520
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
26-
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)
21+
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
2722
|
2823
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
29-
LL | const unsafe fn bar2() -> u32 { unsafe { foo2() } }
30-
|
31-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
32-
|
33-
LL + #[rustc_allow_const_fn_unstable(foo2)]
3424
LL | const unsafe fn bar2() -> u32 { unsafe { foo2() } }
3525
|
3626

@@ -41,14 +31,9 @@ LL | const unsafe fn bar2_gated() -> u32 { unsafe { foo2_gated() } }
4131
| ^^^^^^^^^^^^
4232
|
4333
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
44-
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)
34+
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
4535
|
4636
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
47-
LL | const unsafe fn bar2_gated() -> u32 { unsafe { foo2_gated() } }
48-
|
49-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
50-
|
51-
LL + #[rustc_allow_const_fn_unstable(foo2)]
5237
LL | const unsafe fn bar2_gated() -> u32 { unsafe { foo2_gated() } }
5338
|
5439

tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@ LL | const unsafe fn bar() -> u32 { foo() }
55
| ^^^^^
66
|
77
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
8-
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)
8+
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
99
|
1010
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
11-
LL | const unsafe fn bar() -> u32 { foo() }
12-
|
13-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
14-
|
15-
LL + #[rustc_allow_const_fn_unstable(foo)]
1611
LL | const unsafe fn bar() -> u32 { foo() }
1712
|
1813

@@ -23,14 +18,9 @@ LL | const unsafe fn bar2() -> u32 { foo2() }
2318
| ^^^^^^
2419
|
2520
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
26-
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)
21+
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
2722
|
2823
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
29-
LL | const unsafe fn bar2() -> u32 { foo2() }
30-
|
31-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
32-
|
33-
LL + #[rustc_allow_const_fn_unstable(foo2)]
3424
LL | const unsafe fn bar2() -> u32 { foo2() }
3525
|
3626

@@ -41,14 +31,9 @@ LL | const unsafe fn bar2_gated() -> u32 { foo2_gated() }
4131
| ^^^^^^^^^^^^
4232
|
4333
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
44-
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)
34+
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
4535
|
4636
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
47-
LL | const unsafe fn bar2_gated() -> u32 { foo2_gated() }
48-
|
49-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
50-
|
51-
LL + #[rustc_allow_const_fn_unstable(foo2)]
5237
LL | const unsafe fn bar2_gated() -> u32 { foo2_gated() }
5338
|
5439

tests/ui/consts/min_const_fn/recursive_const_stab_unmarked_crate_imports.stderr

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@ LL | unstable_if_unmarked_const_fn_crate::not_stably_const();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
8-
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)
8+
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
99
|
1010
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
11-
LL | const fn stable_fn() {
12-
|
13-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
14-
|
15-
LL + #[rustc_allow_const_fn_unstable(rustc_private)]
1611
LL | const fn stable_fn() {
1712
|
1813

tests/ui/consts/min_const_fn/recursive_const_stab_unstable_if_unmarked.stderr

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@ LL | not_stably_const();
55
| ^^^^^^^^^^^^^^^^^^
66
|
77
= help: mark the callee as `#[rustc_const_stable_indirect]` if it does not itself require any unstable features
8-
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)
8+
help: if the caller is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
99
|
1010
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
11-
LL | pub const fn expose_on_stable() {
12-
|
13-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
14-
|
15-
LL + #[rustc_allow_const_fn_unstable(rustc_private)]
1611
LL | pub const fn expose_on_stable() {
1712
|
1813

@@ -22,14 +17,9 @@ error: const function that might be (indirectly) exposed to stable cannot use `#
2217
LL | let _x = async { 15 };
2318
| ^^^^^^^^^^^^
2419
|
25-
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)
20+
help: if the function is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
2621
|
2722
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
28-
LL | pub const fn expose_on_stable() {
29-
|
30-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
31-
|
32-
LL + #[rustc_allow_const_fn_unstable(const_async_blocks)]
3323
LL | pub const fn expose_on_stable() {
3424
|
3525

tests/ui/intrinsics/const-eval-select-stability.stderr

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@ error: const function that might be (indirectly) exposed to stable cannot use `#
44
LL | const_eval_select((), nothing, log);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
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)
7+
help: if the function is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
88
|
99
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
10-
LL | pub const fn hey() {
11-
|
12-
help: otherwise, as a last resort `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (this requires team approval)
13-
|
14-
LL + #[rustc_allow_const_fn_unstable(const_eval_select)]
1510
LL | pub const fn hey() {
1611
|
1712

0 commit comments

Comments
 (0)