Skip to content

Commit 9866b09

Browse files
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 3d4467d + bce8621 commit 9866b09

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 17 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 6 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)]

0 commit comments

Comments
 (0)