Skip to content

Suggest surrounding with braces when using a const function with arguments with const generics. #91020

Closed
@hollmmax

Description

@hollmmax

Given the following code: playground

fn foo<const N: i32>() -> i32 {
    N
}

const fn bar() -> i32 {
    1
}

const fn baz(n: i32) -> i32 {
    n
}

pub fn main() {
    foo::<bar()>();
    foo::<baz(1)>();
}

The current output is:

error: expected type, found `1`
  --> src/main.rs:15:15
   |
15 |     foo::<baz(1)>();
   |               ^ expected type

error[E0573]: expected type, found function `bar`
  --> src/main.rs:14:11
   |
14 |     foo::<bar()>();
   |           ^^^^^ not a type

error[E0747]: unresolved item provided when a constant was expected
  --> src/main.rs:14:11
   |
14 |     foo::<bar()>();
   |           ^^^^^
   |
help: if this generic argument was intended as a const parameter, surround it with braces
   |
14 |     foo::<{ bar() }>();
   |           +       +

Some errors have detailed explanations: E0573, E0747.
For more information about an error, try `rustc --explain E0573`.

Ideally the output should also suggest adding braces to foo::<baz(1)>()

Metadata

Metadata

Assignees

Labels

A-const-genericsArea: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions