Skip to content

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

@JulianKnodt

Description

@JulianKnodt
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

Activity

added
A-const-genericsArea: const generics (parameters and arguments)
requires-nightlyThis issue requires a nightly compiler in some way.
on Jul 27, 2020
lcnr

lcnr commented on Jul 27, 2020

@lcnr
Contributor

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

JulianKnodt commented on Jul 27, 2020

@JulianKnodt
ContributorAuthor

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

varkor commented on Sep 28, 2020

@varkor
Member

Closing as expected behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @varkor@JulianKnodt@jyn514@lcnr

        Issue actions

          const-generics & generic default parameter regression on nightly · Issue #74806 · rust-lang/rust