Skip to content

order of type and const generics is different in diagnostics #135737

Closed
@lolbinarycat

Description

@lolbinarycat

Code

struct WeirdArray<const N: usize, T>([T; N]);

fn main() {
    let a1 = WeirdArray::<1, u8>([1]);
    let a2: WeirdArray<2, u8>;
    a2 = a1;
}

Current output

error[E0308]: mismatched types
 --> src/main.rs:6:10
  |
6 |     a2 = a1;
  |          ^^ expected `2`, found `1`
  |
  = note: expected struct `WeirdArray<_, 2>`
             found struct `WeirdArray<_, 1>`

For more information about this error, try `rustc --explain E0308`.

Desired output

error[E0308]: mismatched types
 --> src/main.rs:6:10
  |
6 |     a2 = a1;
  |          ^^ expected `2`, found `1`
  |
  = note: expected struct `WeirdArray<2, _>`
             found struct `WeirdArray<1, _>`

For more information about this error, try `rustc --explain E0308`.

Rationale and extra context

I believe that putting const generics before type generics used to be a compile error, but it certainly isn't anymore.

Other cases

Rust Version

1.84.0

Anything else?

No response

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions