-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
RFC 2203 does not work for Vec::new
#65737
Comments
The |
A comment in
I think explicit (non- If everyone is comfortable with this, I will add it to the rules for promotability. |
@Centril or @nikomatsakis mentioned that we might at some point even allow using run-time expressions for array repeats... in the light of that it might not be a good idea to use the "explicit" rules for promotability. "explicit" is only okay if code would fail to compile when not promoted. |
If the type of the array element is |
Wait, what? I was under the impression that we first check
I think we do. The reason we are so strict is that code might do things (in particular, code inside So, the strict stanza "failure to promote must imply failure to compile" has nothing to do with lifetimes or drop or so. It's all about not breaking people's ability to compile their code. |
For non- If you're not convinced by the above (I'm not entirely convinced either), we should switch to the following rules for promotability and make
I don't think it matters whether we allow |
Did we fix this though? I forget if we actually added that check. |
@eddyb You're correct. On nightly, all array initializers are promoted if the feature is enabled (look at the generated MIR). |
This is what I want that table to look like btw, if not obvious:
The Moving |
While working on this, I've become a bit more concerned about allowing |
It's the same as |
What differentiates that code from the version with `Vec` replacing `Box`
though? How can we justify one without the other?
…On Thu, Oct 24, 2019, 22:16 Eduard-Mihai Burtescu ***@***.***> wrote:
It's the same as const X = Box::new(4); [X, X] - we wouldn't allow that
either, and it wouldn't be based on the presence of Drop.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#65737?email_source=notifications&email_token=AHAZGRB5YYSBQ7ZDXFY4ZQLQQJ6MTA5CNFSM4JEJQIUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECHGS2A#issuecomment-546204008>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHAZGRFOXQ4D5WIKDRFV2H3QQJ6MTANCNFSM4JEJQIUA>
.
|
I don't know, to be honest. That's a question for @oli-obk I guess. EDIT: actually we probably want to allow copying We can make |
Please direct all your const heap related questions to rust-lang/const-eval#20 It is not a problem, because
So you can do |
@oli-obk I think you've fallen again in the trap of assuming no polymorphism. |
Well... we could still allow it for all constants where we can compute a final value, but maybe that's not a good idea |
Oh I see, I misread.
What were you assuming this mechanism would look like?
Agreed.
No please not. My long-term goal is to remove |
…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)
The feature This works, but needs a type annotation: #![feature(inline_const)]
fn main() {
let _: [Vec<i32>; 4] = [const { Vec::<i32>::new() }; 4];
} I think this means we can close this issue? |
RFC 2203 specifically calls out
Vec::new
as a motivating example, however this does not work on the current nightly.There are two reasons for this. First, promotion in array repeat expressions currently uses the "implicit" rules for promotability, which forbids promotion of function calls without
#[rustc_promotable]
. Second, the result ofVec::new()
is marked asNeedsDrop
sinceVec<T>
isDrop
, which disqualifies it from promotion, even in an explicit context.cc #49147
The text was updated successfully, but these errors were encountered: