Closed
Description
As shown in #66884 (comment) const-qualification can ignore some const fn
s, in the context of libcore / rustc crates:
#![stable(feature = "core", since = "1.6.0")]
#![feature(const_if_match)]
#![feature(rustc_const_unstable)]
#![feature(staged_api)]
enum Opt<T> {
Some(T),
None,
}
impl<T> Opt<T> {
#[rustc_const_unstable(feature = "foo")]
#[stable(feature = "rust1", since = "1.0.0")]
const fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T {
match self {
Opt::Some(t) => t,
Opt::None => f(),
}
}
}
This should not compile without "miri unleashed"; const-qualification does not see this function as const since the unstable feature is not enabled, and thus does not check it.
It does not compile outside of libcore, nor if the unstable feature is enabled in libcore.
More discussion is also available in this zulip thread.
I have a fix and will post a PR shortly. There are a couple of existing cases in libcore
where this matters (for const_ptr_offset_from
and const_type_name
), and I'll fix those at the same time.