Skip to content

RFC 2203 not implemented inside a const block #65732

New issue

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

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

Already on GitHub? # to your account

Closed
ecstatic-morse opened this issue Oct 23, 2019 · 0 comments · Fixed by #66642
Closed

RFC 2203 not implemented inside a const block #65732

ecstatic-morse opened this issue Oct 23, 2019 · 0 comments · Fixed by #66642
Assignees
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) B-unstable Blocker: Implemented in the nightly compiler and unstable. C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ecstatic-morse
Copy link
Contributor

ecstatic-morse commented Oct 23, 2019

Thanks to RFC 2203, code like the following compiles on nightly:

fn main() {
    let _: [Option<Box<i32>>; 4] = [None; 4];
}

However, as pointed out by @RalfJung, the same code fails to compile in a const block (Playground):

const _: [Option<Box<i32>>; 4] = [None; 4];

Currently, there's two distinct implementations for promotion of temps, one for fn and const fn and one for const and static. RFC 2203 is implemented for the first but not the second.

I didn't see an actual issue for this. I'll close this as a dupe if @RalfJung already opened one.

cc #49147

@ecstatic-morse ecstatic-morse added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. B-unstable Blocker: Implemented in the nightly compiler and unstable. C-bug Category: This is a bug. A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) labels Oct 23, 2019
@ecstatic-morse ecstatic-morse self-assigned this Oct 23, 2019
@Centril Centril added the requires-nightly This issue requires a nightly compiler in some way. label Oct 24, 2019
Centril added a commit to Centril/rust that referenced this issue Oct 28, 2019
…error, r=ecstatic-morse

suggest `const_in_array_repeat_expression` flag

This PR adds a suggestion to add the `#![feature(const_in_array_repeat_expression)]` attribute to the crate when a promotable expression is used in a repeat expression and the feature gate is not enabled.

Unfortunately, this ended up being a little bit more complex than I anticipated, which may not have been worth it given that this would all be removed when the feature is stabilized. However, with rust-lang#65732 and rust-lang#65737 being open, and the feature gate having not been being suggested to potential users, the feature might not be stabilized in a while, so maybe this is worth landing.

cc @Centril (addresses [this comment](rust-lang#61749 (comment)))
r? @ecstatic-morse (opened issues related to RFC 2203 recently)
@bors bors closed this as completed in bbb664a Nov 28, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) B-unstable Blocker: Implemented in the nightly compiler and unstable. C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. 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