Skip to content

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

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

Closed
lolbinarycat opened this issue Jan 19, 2025 · 0 comments · Fixed by #135749
Closed

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

lolbinarycat opened this issue Jan 19, 2025 · 0 comments · Fixed by #135749
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lolbinarycat
Copy link
Contributor

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

@lolbinarycat lolbinarycat added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 19, 2025
@compiler-errors compiler-errors self-assigned this Jan 19, 2025
@bors bors closed this as completed in ca5fa66 Jan 25, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 25, 2025
Rollup merge of rust-lang#135749 - compiler-errors:param-ordering, r=davidtwco

Do not assume const params are printed after type params

Fixes rust-lang#135737
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants