Discussed in zulip: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Using.20const.20unreachable.20in.20libcore/near/210673352
The problem is that compiler doesn't accept code like this:
#[allow_internal_unstable(const_fn)]
#[allow_internal_unstable(const_unreachable_unchecked)]
pub const fn len(&self) -> usize {
// SAFETY: this is safe because `&[T]` and `FatPtr<T>` have the same layout.
// Only `std` can make this guarantee.
let raw_len = unsafe { crate::ptr::Repr { rust: self }.raw.len };
match mem::size_of::<T>() {
0 => {}
// SAFETY: this branch taken if mathematically `isize::MAX < raw_len * N`.
// But references must point to one allocation with size at most isize::MAX.
N if (isize::MAX as usize) / N < raw_len => unsafe { hint::unreachable_unchecked() },
_ => {}
}
raw_len
}
But it accepts code when merging mutiple allow_internal_unstable annotations into one: #77023
Meta
rustc --version --verbose: Version 1.48.0-nightly (0da5800 2020-09-22)
cc #76807 which modified some const stability checks.
@rustbot modify labels: E-mentor
Discussed in zulip: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Using.20const.20unreachable.20in.20libcore/near/210673352
The problem is that compiler doesn't accept code like this:
But it accepts code when merging mutiple
allow_internal_unstableannotations into one: #77023Meta
rustc --version --verbose: Version 1.48.0-nightly (0da5800 2020-09-22)cc #76807 which modified some const stability checks.
@rustbot modify labels: E-mentor