Skip to content

const_generics: parsing fails with const expression in type parameter #70753

Closed
@jonhoo

Description

@jonhoo

I tried this code:

#![feature(const_generics)]

struct Foo<const N: usize>([(); N]);
type A = Foo<std::mem::size_of::<u8>()>;

It fails to parse with

error: expected one of `!`, `+`, `,`, `::`, or `>`, found `(`
  --> src/lib.rs:12:37
   |
 4 | type A = Foo<std::mem::size_of::<u8>()>;
   |                                     ^ expected one of `!`, `+`, `,`, `::`, or `>`

I assume that this is supposed to work though, since this code is accepted:

const X: usize = std::mem::size_of::<u8>();
type A = Foo<X>;

Meta

rustc --version --verbose:

1.44.0-nightly (2020-04-02 537ccdf3ac44c8c7a8d3)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.F-const_generics`#![feature(const_generics)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.const-generics-bad-diagnosticsAn error is correctly emitted, but is confusing, for `min_const_generics`.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions