Skip to content

Bad error when using a const generic wrong #111110

Open
@asquared31415

Description

@asquared31415

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions