Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ce50939

Browse files
Fix "unstable in stable" error
The "otherwise" note is printed before the suggestion currently.
1 parent 782a595 commit ce50939

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ pub fn non_const<O: NonConstOp>(ccx: &ConstCx<'_, '_>, op: O, span: Span) -> boo
3333
concat!(r#"#[rustc_const_unstable(feature = "...", issue = "...")]"#, '\n').to_owned(),
3434
Applicability::HasPlaceholders,
3535
)
36-
.note("otherwise `#[allow_internal_unstable]` can be used to bypass stability checks")
36+
.span_suggestion(
37+
ccx.body.span,
38+
"otherwise `#[allow_internal_unstable]` can be used to bypass stability checks",
39+
format!("#[allow_internal_unstable({})]", gate),
40+
Applicability:: MaybeIncorrect,
41+
)
3742
.emit();
3843
}
3944

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ error: const-stable function cannot use `#[feature(const_fn_fn_ptr_basics)]`
44
LL | const fn error(_: fn()) {}
55
| ^
66
|
7-
= note: otherwise `#[allow_internal_unstable]` can be used to bypass stability checks
87
help: if it is not part of the public API, make this function unstably const
98
|
109
LL | #[rustc_const_unstable(feature = "...", issue = "...")]
1110
|
11+
help: otherwise `#[allow_internal_unstable]` can be used to bypass stability checks
12+
|
13+
LL | #[allow_internal_unstable(const_fn_fn_ptr_basics)]
14+
|
1215

1316
error: aborting due to previous error
1417

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ error: const-stable function cannot use `#[feature(const_fn_floating_point_arith
2020
LL | const fn bar3() -> u32 { (5f32 + 6f32) as u32 }
2121
| ^^^^^^^^^^^^^
2222
|
23-
= note: otherwise `#[allow_internal_unstable]` can be used to bypass stability checks
2423
help: if it is not part of the public API, make this function unstably const
2524
|
2625
LL | #[rustc_const_unstable(feature = "...", issue = "...")]
2726
|
27+
help: otherwise `#[allow_internal_unstable]` can be used to bypass stability checks
28+
|
29+
LL | #[allow_internal_unstable(const_fn_floating_point_arithmetic)]
30+
|
2831

2932
error: `foo2_gated` is not yet stable as a const fn
3033
--> $DIR/min_const_fn_libstd_stability.rs:39:32

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ error: const-stable function cannot use `#[feature(const_fn_floating_point_arith
2020
LL | const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 }
2121
| ^^^^^^^^^^^^^
2222
|
23-
= note: otherwise `#[allow_internal_unstable]` can be used to bypass stability checks
2423
help: if it is not part of the public API, make this function unstably const
2524
|
2625
LL | #[rustc_const_unstable(feature = "...", issue = "...")]
2726
|
27+
help: otherwise `#[allow_internal_unstable]` can be used to bypass stability checks
28+
|
29+
LL | #[allow_internal_unstable(const_fn_floating_point_arithmetic)]
30+
|
2831

2932
error: `foo2_gated` is not yet stable as a const fn
3033
--> $DIR/min_const_unsafe_fn_libstd_stability.rs:39:48

0 commit comments

Comments
 (0)