-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)C-bugCategory: This is a bug.Category: This is a bug.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
Given that there were many recent changes to const-generics, I don't particularly know if this is an intended change or not. But from the standpoint of an end-user of this feature on nightly, it would appear that something changed that caused downstream things to break without a reference to why. If this was intended, please feel free to close this issue, but I think it might be worthwhile to note what caused this change.
I tried this code:
struct Example<T=f32, const N: usize> {
item: T,
}
I expected to see this happen: Previously, this would compile on nightly without any error.
Instead, this happened: But this now fails to compile with the error:
error: type parameters with a default must be trailing
... omitted hint ....
note: using type defaults and const parameters in the same parameter list is currently not permitted
If I swap the two items, that is also a compiler error.
Meta
rustc --version --verbose
:
rustc 1.47.0-nightly (d6953df14 2020-07-25)
binary: rustc
commit-hash: d6953df14657f5932270ad2b33bccafe6f39fad4
commit-date: 2020-07-25
host: x86_64-apple-darwin
release: 1.47.0-nightly
LLVM version: 10.0
Metadata
Metadata
Assignees
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)C-bugCategory: This is a bug.Category: This is a bug.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
lcnr commentedon Jul 27, 2020
Hi, this is an intentional change made in #74654.
Afaik actually using the type default wasn't possible here (I think
Example<7>
never worked).Were you able to use this somehow?
The current plan is to allow const and type parameters to be unordered and keep the requirement that
parameters with default are last.
This is currently not part of
min_const_generics
however.Yeah, this is why we added the note to the error message: "note: using type defaults and const parameters in the same parameter list is currently not permitted"
We recently landed #74676, so it shouldn't be too difficult to lift the restriction that type params must be in front of const params here. I won't get to this myself in the near future, so if someone is interested, feel free to open a PR for this.
In case you are stuck while trying this, you can always open a topic on zulip or send me a private message there. I would be glad to help.
JulianKnodt commentedon Jul 27, 2020
Ah ok, as long as it was intended that's fine.
I think it was working previously on older versions of nightly (1.45/1.46) and I was able to use it as such.
Edit: I actually didn't create an instance where this worked (I had type aliased the type so it looked like I was using the default type), but it did compile with a default type.
varkor commentedon Sep 28, 2020
Closing as expected behaviour.