Skip to content

Commit d21c427

Browse files
committed
make it possible to enable const_precise_live_drops per-function
1 parent edbc000 commit d21c427

8 files changed

+41
-8
lines changed

Diff for: compiler/rustc_const_eval/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ const_eval_unstable_const_fn = `{$def_path}` is not yet stable as a const fn
419419
const_eval_unstable_in_stable =
420420
const-stable function cannot use `#[feature({$gate})]`
421421
.unstable_sugg = if it is not part of the public API, make this function unstably const
422-
.bypass_sugg = otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
422+
.bypass_sugg = otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (but requires team approval)
423423
424424
const_eval_unterminated_c_string =
425425
reading a null-terminated string starting at {$pointer} with no null found before end of allocation

Diff for: compiler/rustc_const_eval/src/check_consts/post_drop_elaboration.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ use super::check::Qualifs;
99
use super::ops::{self, NonConstOp};
1010
use super::qualifs::{NeedsNonConstDrop, Qualif};
1111
use super::ConstCx;
12+
use crate::check_consts::rustc_allow_const_fn_unstable;
1213

1314
/// Returns `true` if we should use the more precise live drop checker that runs after drop
1415
/// elaboration.
1516
pub fn checking_enabled(ccx: &ConstCx<'_, '_>) -> bool {
16-
// Const-stable functions must always use the stable live drop checker.
17+
// Const-stable functions must always use the stable live drop checker...
1718
if ccx.is_const_stable_const_fn() {
18-
return false;
19+
// ...except if they have the feature flag set via `rustc_allow_const_fn_unstable`.
20+
return rustc_allow_const_fn_unstable(
21+
ccx.tcx,
22+
ccx.body.source.def_id().expect_local(),
23+
sym::const_precise_live_drops,
24+
);
1925
}
2026

2127
ccx.tcx.features().const_precise_live_drops

Diff for: tests/ui/consts/min_const_fn/allow_const_fn_ptr_run_pass.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
//@ run-pass
2-
#![feature(rustc_allow_const_fn_unstable)]
3-
42
#![feature(rustc_attrs, staged_api)]
53
#![stable(feature = "rust1", since = "1.0.0")]
64

Diff for: tests/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ help: if it is not part of the public API, make this function unstably const
2525
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
2626
LL | const fn bar3() -> u32 { (5f32 + 6f32) as u32 }
2727
|
28-
help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
28+
help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (but requires team approval)
2929
|
3030
LL + #[rustc_allow_const_fn_unstable(const_fn_floating_point_arithmetic)]
3131
LL | const fn bar3() -> u32 { (5f32 + 6f32) as u32 }

Diff for: tests/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ help: if it is not part of the public API, make this function unstably const
2525
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
2626
LL | const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 }
2727
|
28-
help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
28+
help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (but requires team approval)
2929
|
3030
LL + #[rustc_allow_const_fn_unstable(const_fn_floating_point_arithmetic)]
3131
LL | const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0493]: destructor of `Option<T>` cannot be evaluated at compile-time
2+
--> $DIR/precise-drop-allow-const-fn-unstable.rs:11:24
3+
|
4+
LL | pub const fn unwrap<T>(this: Option<T>) -> T {
5+
| ^^^^ the destructor for this type cannot be evaluated in constant functions
6+
...
7+
LL | }
8+
| - value is dropped here
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0493`.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ revisions: allow not_allow
2+
//@ compile-flags: --crate-type=lib -Cinstrument-coverage -Zno-profiler-runtime
3+
//@[allow] check-pass
4+
5+
#![feature(staged_api, rustc_allow_const_fn_unstable)]
6+
#![stable(feature = "rust_test", since = "1.0.0")]
7+
8+
#[stable(feature = "rust_test", since = "1.0.0")]
9+
#[rustc_const_stable(feature = "rust_test", since = "1.0.0")]
10+
#[cfg_attr(allow, rustc_allow_const_fn_unstable(const_precise_live_drops))]
11+
pub const fn unwrap<T>(this: Option<T>) -> T {
12+
//[not_allow]~^ ERROR: cannot be evaluated
13+
match this {
14+
Some(x) => x,
15+
None => panic!(),
16+
}
17+
}

Diff for: tests/ui/internal/internal-unstable-const.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ help: if it is not part of the public API, make this function unstably const
99
LL + #[rustc_const_unstable(feature = "...", issue = "...")]
1010
LL | pub const fn foo() -> f32 {
1111
|
12-
help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
12+
help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks (but requires team approval)
1313
|
1414
LL + #[rustc_allow_const_fn_unstable(const_fn_floating_point_arithmetic)]
1515
LL | pub const fn foo() -> f32 {

0 commit comments

Comments
 (0)