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

Regression for #![feature(const_in_array_repeat_expressions)] #77138

Closed
josephlr opened this issue Sep 24, 2020 · 4 comments
Closed

Regression for #![feature(const_in_array_repeat_expressions)] #77138

josephlr opened this issue Sep 24, 2020 · 4 comments
Labels
C-bug Category: This is a bug.

Comments

@josephlr
Copy link
Contributor

The following code used to compile on nightly, but now does not:

#![feature(const_in_array_repeat_expressions)]

struct T;

impl T {
    const fn new() -> Self {
        Self
    }
}

const fn bar() -> [T; 2] {
    [T::new(); 2]
}

Note that

static FOO: [T; 2] = [T::new(); 2];

still compiles. Adding #![feature(const_fn)] doesn't affect this issue.

I think this regression was introduced in either #76807 or #76850

CC: @ecstatic-morse @oli-obk

@josephlr josephlr added the C-bug Category: This is a bug. label Sep 24, 2020
@josephlr
Copy link
Contributor Author

Actually @RalfJung this might be caused by #76411, as this seems to be a promotion issue.

@RalfJung
Copy link
Member

RalfJung commented Sep 24, 2020

No, this is caused by #75502. We used to incorrectly apply const-promotion rules inside const fn, but since const fn are also fn, that has all the same problems as applying those rules in fn. We still allow this in static and const as those are never subject to codegen, which makes promotion much less risky. (Less risky, but still problematic -- this particular feature will require some annoying quirks all over the compiler if we cannot take it back.)

So, this was never intended to work, and worked by accident. To make this work we'd have to change array initializers to explicit promotion rules, which IIRC we already have an issue for?

See https://github.com/rust-lang/const-eval/blob/master/promotion.md for some background.

@RalfJung
Copy link
Member

Hm, looks like we do not have an issue open for this, but the tracking issue probably makes sense as a place for this discussion: #49147.

@josephlr
Copy link
Contributor Author

Hm, looks like we do not have an issue open for this, but the tracking issue probably makes sense as a place for this discussion: #49147.

Makes sense, we can continue discussion in the tracking issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants