Closed
Description
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
Metadata
Metadata
Assignees
Labels
Area: Attributes (`#[…]`, `#![…]`)Category: This is a bug.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Relevant to the compiler team, which will review and decide on the PR/issue.