Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unstable const fns in libcore can be ignored by const-qualification #67053

Closed
lqd opened this issue Dec 5, 2019 · 0 comments · Fixed by #67055
Closed

unstable const fns in libcore can be ignored by const-qualification #67053

lqd opened this issue Dec 5, 2019 · 0 comments · Fixed by #67055
Assignees
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-stability Area: `#[stable]`, `#[unstable]` etc. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lqd
Copy link
Member

lqd commented Dec 5, 2019

As shown in #66884 (comment) const-qualification can ignore some const fns, 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(),
        }
    }
}

playground

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.

cc @ecstatic-morse @oli-obk

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.

@jonas-schievink jonas-schievink added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-const-fn A-stability Area: `#[stable]`, `#[unstable]` etc. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 5, 2019
@lqd lqd self-assigned this Dec 5, 2019
@bors bors closed this as completed in a008aff Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-stability Area: `#[stable]`, `#[unstable]` etc. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants