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)
This commit is contained in:
Jubilee 2021-10-04 13:58:17 -07:00 committed by GitHub
commit 9866b090f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
51 changed files with 100 additions and 229 deletions

View file

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