Skip to content
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

const-generics & generic default parameter regression on nightly #74806

Closed
JulianKnodt opened this issue Jul 27, 2020 · 3 comments
Closed

const-generics & generic default parameter regression on nightly #74806

JulianKnodt opened this issue Jul 27, 2020 · 3 comments
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way.

Comments

@JulianKnodt
Copy link
Contributor

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
@JulianKnodt JulianKnodt added the C-bug Category: This is a bug. label Jul 27, 2020
@jyn514 jyn514 added A-const-generics Area: const generics (parameters and arguments) requires-nightly This issue requires a nightly compiler in some way. labels Jul 27, 2020
@lcnr
Copy link
Contributor

lcnr commented 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.

struct Example<const N: usize,T = f32> {
  item: T,
}

This is currently not part of min_const_generics however.

If I swap the two items, that is also a compiler error.

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
Copy link
Contributor Author

JulianKnodt commented 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
Copy link
Member

varkor commented Sep 28, 2020

Closing as expected behaviour.

@varkor varkor closed this as completed Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

No branches or pull requests

4 participants