-
Notifications
You must be signed in to change notification settings - Fork 13.3k
On-demand const verification may be a backwards compatibility hazard #19265
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
Comments
With this PR, the following code works: ``` #![feature(tuple_indexing)] struct MyStruct { field1: uint } const S: MyStruct = MyStruct { field1: 42u }; const T: (uint,) = (42u,); struct ConstCheck { array1: [int, ..S.field1], array2: [int, ..T.0], } ``` Closes rust-lang#19244 Related rust-lang#19265
P-low, not 1.0 |
I am not sure how bad this is. There are constants that we cannot evaluate at type-checking time but only at trans time. Eventually I think we can (and should) make that distinction very small or even non-existant, but I don't think it means that those constants can't exist in the first place (which seems to be what @huonw is suggesting). |
Related issue: #3170 (comment) const ARR: [u32; 0] = []; const X: u32 = ARR[5]; The above doesn't error until you do |
I've updated the issue description so that it matches what's happening today. @oli-obk's example is more interesting const X: usize = [][5];
// Uncomment to get an indexing feature-gating constant evaluation error.
// type Foo = [u8; X]; |
This has been solved. All exported constants are checked even if unused |
…gling-dyn-diagnostic feat: Add diagnostic for dangling dyn and impl
E.g. #19244 describes how the following is valid, but uncommenting the line causes the error given below.
(NB. that specific instance may be fixed in future, but that does not necessarily mean this bug is fixed.)
That is, the const-suitability of the value is checked when used as a constant expression, not at the definition. This could possibly may lead to surprises if rules are tweaked (at least, it could lead to surprises that are not detected). In any case, it is certainly confusing for a
const
to apparently be an unsupported constant expression.It seems that we could check the definitions, not just checking them lazily when they are used as const expressions.
The text was updated successfully, but these errors were encountered: