Skip to content

Commit 2914d1d

Browse files
authored
Rollup merge of #89508 - jhpratt:stabilize-const_panic, r=joshtriplett
Stabilize `const_panic` Closes #51999 FCP completed in #89006 `@rustbot` label +A-const-eval +A-const-fn +T-lang cc `@oli-obk` for review (not `r?`'ing as not on lang team)
2 parents ecd5bb8 + bce8621 commit 2914d1d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+100
-229
lines changed

compiler/rustc_borrowck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
#![feature(bool_to_option)]
44
#![feature(box_patterns)]
5-
#![feature(const_panic)]
5+
#![cfg_attr(bootstrap, feature(const_panic))]
66
#![feature(crate_visibility_modifier)]
77
#![feature(format_args_capture)]
88
#![feature(in_band_lifetimes)]

compiler/rustc_const_eval/src/transform/check_consts/check.rs

-2
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,6 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> {
887887

888888
// At this point, we are calling a function, `callee`, whose `DefId` is known...
889889
if is_lang_panic_fn(tcx, callee) {
890-
self.check_op(ops::Panic);
891-
892890
// `begin_panic` and `panic_display` are generic functions that accept
893891
// types other than str. Check to enforce that only str can be used in
894892
// const-eval.

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

-17
Original file line numberDiff line numberDiff line change
@@ -368,23 +368,6 @@ impl NonConstOp for MutDeref {
368368
}
369369
}
370370

371-
#[derive(Debug)]
372-
pub struct Panic;
373-
impl NonConstOp for Panic {
374-
fn status_in_item(&self, _: &ConstCx<'_, '_>) -> Status {
375-
Status::Unstable(sym::const_panic)
376-
}
377-
378-
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
379-
feature_err(
380-
&ccx.tcx.sess.parse_sess,
381-
sym::const_panic,
382-
span,
383-
&format!("panicking in {}s is unstable", ccx.const_kind()),
384-
)
385-
}
386-
}
387-
388371
/// A call to a `panic()` lang item where the first argument is _not_ a `&str`.
389372
#[derive(Debug)]
390373
pub struct PanicNonStr;

compiler/rustc_data_structures/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#![feature(associated_type_bounds)]
1212
#![feature(auto_traits)]
1313
#![feature(bool_to_option)]
14-
#![feature(const_panic)]
14+
#![cfg_attr(bootstrap, feature(const_panic))]
1515
#![feature(control_flow_enum)]
1616
#![feature(core_intrinsics)]
1717
#![feature(extend_one)]

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ declare_features! (
297297
(accepted, arbitrary_enum_discriminant, "1.56.0", Some(60553), None),
298298
/// Allows macro attributes to observe output of `#[derive]`.
299299
(accepted, macro_attributes_in_derive_output, "1.57.0", Some(81119), None),
300+
/// Allows panicking during const eval (producing compile-time errors).
301+
(accepted, const_panic, "1.57.0", Some(51999), None),
300302

301303
// -------------------------------------------------------------------------
302304
// feature-group-end: accepted features

compiler/rustc_feature/src/active.rs

-3
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,6 @@ declare_features! (
425425
/// Allows using the `amdgpu-kernel` ABI.
426426
(active, abi_amdgpu_kernel, "1.29.0", Some(51575), None),
427427

428-
/// Allows panicking during const eval (producing compile-time errors).
429-
(active, const_panic, "1.30.0", Some(51999), None),
430-
431428
/// Allows `#[marker]` on certain traits allowing overlapping implementations.
432429
(active, marker_trait_attr, "1.30.0", Some(29864), None),
433430

compiler/rustc_index/src/vec.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ macro_rules! newtype_index {
124124

125125
#[inline]
126126
$v const fn from_usize(value: usize) -> Self {
127-
// FIXME: replace with `assert!(value <= ($max as usize));` once `const_panic` is stable
127+
#[cfg(not(bootstrap))]
128+
assert!(value <= ($max as usize));
129+
#[cfg(bootstrap)]
128130
[()][(value > ($max as usize)) as usize];
129131
unsafe {
130132
Self::from_u32_unchecked(value as u32)
@@ -133,7 +135,9 @@ macro_rules! newtype_index {
133135

134136
#[inline]
135137
$v const fn from_u32(value: u32) -> Self {
136-
// FIXME: replace with `assert!(value <= $max);` once `const_panic` is stable
138+
#[cfg(not(bootstrap))]
139+
assert!(value <= $max);
140+
#[cfg(bootstrap)]
137141
[()][(value > $max) as usize];
138142
unsafe {
139143
Self::from_u32_unchecked(value)

compiler/rustc_mir_dataflow/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![feature(bool_to_option)]
33
#![feature(box_patterns)]
44
#![feature(box_syntax)]
5-
#![feature(const_panic)]
5+
#![cfg_attr(bootstrap, feature(const_panic))]
66
#![feature(exact_size_is_empty)]
77
#![feature(in_band_lifetimes)]
88
#![feature(iter_zip)]

compiler/rustc_mir_transform/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![feature(box_patterns)]
22
#![feature(box_syntax)]
33
#![feature(crate_visibility_modifier)]
4-
#![feature(const_panic)]
4+
#![cfg_attr(bootstrap, feature(const_panic))]
55
#![feature(in_band_lifetimes)]
66
#![feature(iter_zip)]
77
#![feature(map_try_insert)]

library/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
#![feature(const_fn_trait_bound)]
125125
#![feature(const_impl_trait)]
126126
#![feature(const_mut_refs)]
127-
#![feature(const_panic)]
127+
#![cfg_attr(bootstrap, feature(const_panic))]
128128
#![feature(const_precise_live_drops)]
129129
#![feature(const_raw_ptr_deref)]
130130
#![feature(const_refs_to_cell)]

src/test/mir-opt/remove-never-const.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// Force generation of optimized mir for functions that do not reach codegen.
66
// compile-flags: --emit mir,link
77

8-
#![feature(const_panic)]
98
#![feature(never_type)]
109
#![warn(const_err)]
1110

Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// MIR for `no_codegen` after PreCodegen
22

33
fn no_codegen() -> () {
4-
let mut _0: (); // return place in scope 0 at $DIR/remove-never-const.rs:19:20: 19:20
4+
let mut _0: (); // return place in scope 0 at $DIR/remove-never-const.rs:18:20: 18:20
55
scope 1 {
66
}
77

88
bb0: {
9-
unreachable; // scope 0 at $DIR/remove-never-const.rs:20:13: 20:33
9+
unreachable; // scope 0 at $DIR/remove-never-const.rs:19:13: 19:33
1010
}
1111
}

src/test/ui/consts/const-eval/const_panic.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(const_panic)]
21
#![allow(non_fmt_panics)]
32
#![crate_type = "lib"]
43

src/test/ui/consts/const-eval/const_panic.stderr

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,96 @@
11
error[E0080]: evaluation of constant value failed
2-
--> $DIR/const_panic.rs:7:15
2+
--> $DIR/const_panic.rs:6:15
33
|
44
LL | const Z: () = std::panic!("cheese");
5-
| ^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'cheese', $DIR/const_panic.rs:7:15
5+
| ^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'cheese', $DIR/const_panic.rs:6:15
66
|
77
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
error[E0080]: evaluation of constant value failed
10-
--> $DIR/const_panic.rs:10:16
10+
--> $DIR/const_panic.rs:9:16
1111
|
1212
LL | const Z2: () = std::panic!();
13-
| ^^^^^^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/const_panic.rs:10:16
13+
| ^^^^^^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/const_panic.rs:9:16
1414
|
1515
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
1616

1717
error[E0080]: evaluation of constant value failed
18-
--> $DIR/const_panic.rs:13:15
18+
--> $DIR/const_panic.rs:12:15
1919
|
2020
LL | const Y: () = std::unreachable!();
21-
| ^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:13:15
21+
| ^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:12:15
2222
|
2323
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
2424

2525
error[E0080]: evaluation of constant value failed
26-
--> $DIR/const_panic.rs:16:15
26+
--> $DIR/const_panic.rs:15:15
2727
|
2828
LL | const X: () = std::unimplemented!();
29-
| ^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'not implemented', $DIR/const_panic.rs:16:15
29+
| ^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'not implemented', $DIR/const_panic.rs:15:15
3030
|
3131
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
3232

3333
error[E0080]: evaluation of constant value failed
34-
--> $DIR/const_panic.rs:19:15
34+
--> $DIR/const_panic.rs:18:15
3535
|
3636
LL | const W: () = std::panic!(MSG);
37-
| ^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic.rs:19:15
37+
| ^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic.rs:18:15
3838
|
3939
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
4040

4141
error[E0080]: evaluation of constant value failed
42-
--> $DIR/const_panic.rs:22:16
42+
--> $DIR/const_panic.rs:21:16
4343
|
4444
LL | const W2: () = std::panic!("{}", MSG);
45-
| ^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic.rs:22:16
45+
| ^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic.rs:21:16
4646
|
4747
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
4848

4949
error[E0080]: evaluation of constant value failed
50-
--> $DIR/const_panic.rs:25:20
50+
--> $DIR/const_panic.rs:24:20
5151
|
5252
LL | const Z_CORE: () = core::panic!("cheese");
53-
| ^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'cheese', $DIR/const_panic.rs:25:20
53+
| ^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'cheese', $DIR/const_panic.rs:24:20
5454
|
5555
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
5656

5757
error[E0080]: evaluation of constant value failed
58-
--> $DIR/const_panic.rs:28:21
58+
--> $DIR/const_panic.rs:27:21
5959
|
6060
LL | const Z2_CORE: () = core::panic!();
61-
| ^^^^^^^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/const_panic.rs:28:21
61+
| ^^^^^^^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/const_panic.rs:27:21
6262
|
6363
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
6464

6565
error[E0080]: evaluation of constant value failed
66-
--> $DIR/const_panic.rs:31:20
66+
--> $DIR/const_panic.rs:30:20
6767
|
6868
LL | const Y_CORE: () = core::unreachable!();
69-
| ^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:31:20
69+
| ^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:30:20
7070
|
7171
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
7272

7373
error[E0080]: evaluation of constant value failed
74-
--> $DIR/const_panic.rs:34:20
74+
--> $DIR/const_panic.rs:33:20
7575
|
7676
LL | const X_CORE: () = core::unimplemented!();
77-
| ^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'not implemented', $DIR/const_panic.rs:34:20
77+
| ^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'not implemented', $DIR/const_panic.rs:33:20
7878
|
7979
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
8080

8181
error[E0080]: evaluation of constant value failed
82-
--> $DIR/const_panic.rs:37:20
82+
--> $DIR/const_panic.rs:36:20
8383
|
8484
LL | const W_CORE: () = core::panic!(MSG);
85-
| ^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic.rs:37:20
85+
| ^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic.rs:36:20
8686
|
8787
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
8888

8989
error[E0080]: evaluation of constant value failed
90-
--> $DIR/const_panic.rs:40:21
90+
--> $DIR/const_panic.rs:39:21
9191
|
9292
LL | const W2_CORE: () = core::panic!("{}", MSG);
93-
| ^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic.rs:40:21
93+
| ^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic.rs:39:21
9494
|
9595
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
9696

src/test/ui/consts/const-eval/const_panic_2021.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// edition:2021
2-
#![feature(const_panic)]
32
#![crate_type = "lib"]
43

54
const MSG: &str = "hello";

src/test/ui/consts/const-eval/const_panic_2021.stderr

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,80 @@
11
error[E0080]: evaluation of constant value failed
2-
--> $DIR/const_panic_2021.rs:7:15
2+
--> $DIR/const_panic_2021.rs:6:15
33
|
44
LL | const A: () = std::panic!("blåhaj");
5-
| ^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'blåhaj', $DIR/const_panic_2021.rs:7:15
5+
| ^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'blåhaj', $DIR/const_panic_2021.rs:6:15
66
|
77
= note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
error[E0080]: evaluation of constant value failed
10-
--> $DIR/const_panic_2021.rs:10:15
10+
--> $DIR/const_panic_2021.rs:9:15
1111
|
1212
LL | const B: () = std::panic!();
13-
| ^^^^^^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/const_panic_2021.rs:10:15
13+
| ^^^^^^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/const_panic_2021.rs:9:15
1414
|
1515
= note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info)
1616

1717
error[E0080]: evaluation of constant value failed
18-
--> $DIR/const_panic_2021.rs:13:15
18+
--> $DIR/const_panic_2021.rs:12:15
1919
|
2020
LL | const C: () = std::unreachable!();
21-
| ^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_2021.rs:13:15
21+
| ^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_2021.rs:12:15
2222
|
2323
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
2424

2525
error[E0080]: evaluation of constant value failed
26-
--> $DIR/const_panic_2021.rs:16:15
26+
--> $DIR/const_panic_2021.rs:15:15
2727
|
2828
LL | const D: () = std::unimplemented!();
29-
| ^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'not implemented', $DIR/const_panic_2021.rs:16:15
29+
| ^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'not implemented', $DIR/const_panic_2021.rs:15:15
3030
|
3131
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
3232

3333
error[E0080]: evaluation of constant value failed
34-
--> $DIR/const_panic_2021.rs:19:15
34+
--> $DIR/const_panic_2021.rs:18:15
3535
|
3636
LL | const E: () = std::panic!("{}", MSG);
37-
| ^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic_2021.rs:19:15
37+
| ^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic_2021.rs:18:15
3838
|
3939
= note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info)
4040

4141
error[E0080]: evaluation of constant value failed
42-
--> $DIR/const_panic_2021.rs:22:20
42+
--> $DIR/const_panic_2021.rs:21:20
4343
|
4444
LL | const A_CORE: () = core::panic!("shark");
45-
| ^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'shark', $DIR/const_panic_2021.rs:22:20
45+
| ^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'shark', $DIR/const_panic_2021.rs:21:20
4646
|
4747
= note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info)
4848

4949
error[E0080]: evaluation of constant value failed
50-
--> $DIR/const_panic_2021.rs:25:20
50+
--> $DIR/const_panic_2021.rs:24:20
5151
|
5252
LL | const B_CORE: () = core::panic!();
53-
| ^^^^^^^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/const_panic_2021.rs:25:20
53+
| ^^^^^^^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/const_panic_2021.rs:24:20
5454
|
5555
= note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info)
5656

5757
error[E0080]: evaluation of constant value failed
58-
--> $DIR/const_panic_2021.rs:28:20
58+
--> $DIR/const_panic_2021.rs:27:20
5959
|
6060
LL | const C_CORE: () = core::unreachable!();
61-
| ^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_2021.rs:28:20
61+
| ^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_2021.rs:27:20
6262
|
6363
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
6464

6565
error[E0080]: evaluation of constant value failed
66-
--> $DIR/const_panic_2021.rs:31:20
66+
--> $DIR/const_panic_2021.rs:30:20
6767
|
6868
LL | const D_CORE: () = core::unimplemented!();
69-
| ^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'not implemented', $DIR/const_panic_2021.rs:31:20
69+
| ^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'not implemented', $DIR/const_panic_2021.rs:30:20
7070
|
7171
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
7272

7373
error[E0080]: evaluation of constant value failed
74-
--> $DIR/const_panic_2021.rs:34:20
74+
--> $DIR/const_panic_2021.rs:33:20
7575
|
7676
LL | const E_CORE: () = core::panic!("{}", MSG);
77-
| ^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic_2021.rs:34:20
77+
| ^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'hello', $DIR/const_panic_2021.rs:33:20
7878
|
7979
= note: this error originates in the macro `$crate::panic::panic_2021` (in Nightly builds, run with -Z macro-backtrace for more info)
8080

src/test/ui/consts/const-eval/const_panic_libcore_bin.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![crate_type = "bin"]
22
#![feature(lang_items)]
3-
#![feature(const_panic)]
43
#![no_main]
54
#![no_std]
65

0 commit comments

Comments
 (0)