You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test2.rs:7:11: 7:21 error: expected constant expr for vector length: Can't cast str to int
test2.rs:7 let x: [int, ..i] = [1, 2, 3, 4];
^~~~~~~~~~
That error message doesn't seem to make sense, but that may be because it's just confused - I also get this error message in other circumstances, and I don't understand what the difference is:
It seems like the constant checker believes that Bar is a constant, whereas the constant evaluator does not. They should agree. I'm not sure which behavior is right. Also, it seems counter-intuitive that you can't refer to a constant (i) in other constants.
I'm doubtful that the earlier testcase ever worked; 877bba9 explicitly calls out in the commit message that C style enums don't work in type signatures, only values.
@tommit I was not attempting to claim that it was a language feature that these aren't compile-time constants. (I do concede that my earlier response can be interpreted that way.)
I was trying to claim that changing the current language to treat them as compile-time constants would be a language feature, and thus should go through the RFC process. (After all, a ticket like this really isn't the appropriate venue to debate the value of such a change.)
Here's the essence of what I was thinking when I wrote that response: I have been long under the impression that we were reserving the right to change how discriminant values are assigned by the compiler if not explicitly assigned by programmer.
(Of course actually allowing such a change would probably require restricting the current language; i.e. Variant as Type when Variant would need to be outlawed during dynamic execution in addition to it being disallowed at compile time. And I imagine we could not do that unless we simultaneously accepted rust-lang/rfcs#639 and probably provided a stable API to that RFC as well.)
Its quite possible that my mental model of what we were planning to permit in the future was simply over-aggressive; i.e. that no one else on the team was planning on ever changing the assignment of discriminant values, at least not for enum variants that do not have a data payload attached.
reopening and putting on agenda for next meeting; this deserves discussion at the team meeting, if only to get clarification about what guarantees we plan with respect to discriminant value assignment.
So after discussing with @nikomatsakis i concluded that my mental model is simply wrong, and that there is not sufficient value in trying to future-proof our future discriminant value assignment. In particular @nikomatsakis pointed out to me multiple times that the chosen discriminant value need not be directly represented as the numeric value chosen; thus various tricks I was anticipating (usually revolving around ensuring that e.g. bit patterns are non-zero) should be able to be adopted in the future.
Anyway, the bugs been reopened; we should fix this, for consistency's sake.
(In some sense this is a feature request, or at least a request for consistently deploying a particular feature. Fixing this may be important when/if const fn comes, but its hard to tell right now.)
Decided to file a fresh issue, #23898, to ease triage. (I.e. right now the main item left on this bug is hard to actually extract from the thread of conversation as presented.)
Activity
auto merge of #5890 : youknowone/rust/const-eval, r=catamorphism
Prevent eval_const_expr_partial hides prior error in expr_cast arm.
catamorphism commentedon Jun 3, 2013
It seems like the constant checker believes that
Baris a constant, whereas the constant evaluator does not. They should agree. I'm not sure which behavior is right. Also, it seems counter-intuitive that you can't refer to a constant (i) in other constants.Nominating for milestone 1, welll-defined.
huonw commentedon Jul 30, 2013
Works now. Fixed by 877bba9 (possibly; at the very least, it includes a testcase).
tikue commentedon Aug 28, 2013
This doesn't seem to work now.
$ x86_64-apple-darwin/stage2/bin/rust run static_test.rs
static_test.rs:10:24: 10:52 error: expected constant expr for vector length: Non-constant path in constant expr
static_test.rs:10 let the_categories: [Category, ..NUM_CATEGORIES] = [A, B, C];
jdm commentedon Aug 28, 2013
I'm doubtful that the earlier testcase ever worked; 877bba9 explicitly calls out in the commit message that C style enums don't work in type signatures, only values.
pnkfelix commentedon Aug 29, 2013
Part of #5551; inherits its maturity milestone implicitly.
17 remaining items
pnkfelix commentedon Mar 8, 2015
I might be wrong on this point; I will check more carefully when I am in front of a computer again
pnkfelix commentedon Mar 8, 2015
@tommit I was not attempting to claim that it was a language feature that these aren't compile-time constants. (I do concede that my earlier response can be interpreted that way.)
I was trying to claim that changing the current language to treat them as compile-time constants would be a language feature, and thus should go through the RFC process. (After all, a ticket like this really isn't the appropriate venue to debate the value of such a change.)
Here's the essence of what I was thinking when I wrote that response: I have been long under the impression that we were reserving the right to change how discriminant values are assigned by the compiler if not explicitly assigned by programmer.
(Of course actually allowing such a change would probably require restricting the current language; i.e.
Variant as TypewhenVariantwould need to be outlawed during dynamic execution in addition to it being disallowed at compile time. And I imagine we could not do that unless we simultaneously accepted rust-lang/rfcs#639 and probably provided a stable API to that RFC as well.)Its quite possible that my mental model of what we were planning to permit in the future was simply over-aggressive; i.e. that no one else on the team was planning on ever changing the assignment of discriminant values, at least not for enum variants that do not have a data payload attached.
pnkfelix commentedon Mar 8, 2015
reopening and putting on agenda for next meeting; this deserves discussion at the team meeting, if only to get clarification about what guarantees we plan with respect to discriminant value assignment.
nikomatsakis commentedon Mar 10, 2015
Hmm, I tend to agree with @tommit that it should work for both explicitly assigned and unassigned values, if it works at all.
nikomatsakis commentedon Mar 10, 2015
(I didn't fully appreciate when commenting before that it worked only in one case and not the other.)
pnkfelix commentedon Mar 12, 2015
So after discussing with @nikomatsakis i concluded that my mental model is simply wrong, and that there is not sufficient value in trying to future-proof our future discriminant value assignment. In particular @nikomatsakis pointed out to me multiple times that the chosen discriminant value need not be directly represented as the numeric value chosen; thus various tricks I was anticipating (usually revolving around ensuring that e.g. bit patterns are non-zero) should be able to be adopted in the future.
Anyway, the bugs been reopened; we should fix this, for consistency's sake.
pnkfelix commentedon Mar 12, 2015
triage: P-high
(In some sense this is a feature request, or at least a request for consistently deploying a particular feature. Fixing this may be important when/if
const fncomes, but its hard to tell right now.)pnkfelix commentedon Mar 31, 2015
Decided to file a fresh issue, #23898, to ease triage. (I.e. right now the main item left on this bug is hard to actually extract from the thread of conversation as presented.)
Merge rust-lang#5873