-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-stabilityArea: `#[stable]`, `#[unstable]` etc.Area: `#[stable]`, `#[unstable]` etc.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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.
hadronized and ecstatic-morse
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-stabilityArea: `#[stable]`, `#[unstable]` etc.Area: `#[stable]`, `#[unstable]` etc.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.