Skip to content

Recover and suggest wrapping in block in const generic value application #61175

Closed
@Centril

Description

@Centril

cc @varkor @rust-lang/wg-diagnostics

Say we have:

#![feature(const_generics)]

fn foo<const N: usize>() {}

fn bar() {
    foo::<1 + 1>();
}

the parser now greets you with:

error: expected one of `,` or `>`, found `+`
 --> src/lib.rs:6:13
  |
6 |     foo::<1 + 1>();
  |             ^ expected one of `,` or `>` here

It would be good if you got:

error: expected one of `,` or `>`, found `+`
 --> src/lib.rs:6:13
  |
6 |     foo::<1 + 1>();
  |             ^ expected one of `,` or `>` here
  |
  | help: wrap the expression in a block:
6 |     foo::<{1 + 1}>();

or some such.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.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`.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions