Skip to content

Bad error when using a const generic wrong #111110

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

Open
asquared31415 opened this issue May 2, 2023 · 2 comments
Open

Bad error when using a const generic wrong #111110

asquared31415 opened this issue May 2, 2023 · 2 comments
Labels
A-const-generics Area: const generics (parameters and arguments) A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked.

Comments

@asquared31415
Copy link
Contributor

The following code:

fn uwu<const N: usize>() {
    let _ = [0; N{}];
}

produces the error

error: generic parameters may not be used in const operations
 --> src/lib.rs:2:17
  |
2 |     let _ = [0; N{}];
  |                 ^ cannot perform const operation using `N`
  |
  = help: const parameters may only be used as standalone arguments, i.e. `N`

however, when enabling feature(generic_const_exprs), the error changes to

error[[E0574]](https://doc.rust-lang.org/nightly/error_codes/E0574.html): expected struct, variant or union type, found const parameter `N`
--> src/lib.rs:4:17
|
4 |     let _ = [0; N{}];
|                 ^ not a struct, variant or union type

The error on stable should change to be the same as the error with generic_const_exprs enabled.

On stable, it's probably more likely that the user doesn't want the generic to be const, or wants to remove the {} than them trying to actually do anything with generic_const_exprs.

@Jules-Bertholet
Copy link
Contributor

@rustbot label +A-const-generics +A-diagnostics +D-confusing

@rustbot rustbot added A-const-generics Area: const generics (parameters and arguments) A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. labels May 3, 2023
@joseluis
Copy link
Contributor

Related or duplicate of #79429

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) A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked.
Projects
None yet
Development

No branches or pull requests

4 participants