Skip to content
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

Provide more helpful error message when trying to use const generic defaults #80507

Closed
XAMPPRocky opened this issue Dec 30, 2020 · 1 comment · Fixed by #80547
Closed

Provide more helpful error message when trying to use const generic defaults #80507

XAMPPRocky opened this issue Dec 30, 2020 · 1 comment · Fixed by #80547
Labels
A-const-generics Area: const generics (parameters and arguments) A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. const-generics-bad-diagnostics An error is correctly emitted, but is confusing, for `min_const_generics`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@XAMPPRocky
Copy link
Member

XAMPPRocky commented Dec 30, 2020

Defaults are currently not implemented in const generics. With min_const_generics stabilising soon, I've been using them more and one thing that is surprising is the lack of defaults. Especially when you try to declare a default, the error message provides a unexpected syntax error, when I would expect a "defaults in const generics is not implemented" error, leading you to think that there's another syntax that you need to use as opposed to it just not being available.

#![feature(min_const_generics)]

fn foo<const NUM: usize = 0>() -> usize {
    NUM
}

Error Message

error: expected one of `!`, `(`, `+`, `,`, `::`, `<`, or `>`, found `=`
 --> src/lib.rs:3:25
  |
3 | fn foo<const NUM: usize = 0>() -> usize {
  |                         ^ expected one of 7 possible tokens

error: aborting due to previous error
@XAMPPRocky XAMPPRocky added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-const-generics Area: const generics (parameters and arguments) F-min_const_generics const-generics-bad-diagnostics An error is correctly emitted, but is confusing, for `min_const_generics`. labels Dec 30, 2020
@jonas-schievink jonas-schievink added the A-parser Area: The parsing of Rust source code to an AST label Dec 30, 2020
@varkor
Copy link
Member

varkor commented Dec 30, 2020

Perhaps the simplest solution is to extract the parsing for const generic defaults from #75384, but unconditionally emit an error in ast_validation.rs if they're used. I think it's very likely we'll want to support const generic defaults before too long, so hopefully the solution is going to be temporary anyway.

cc @JulianKnodt in case you're interested in implementing this, from your experience with #75384.

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 A-parser Area: The parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. const-generics-bad-diagnostics An error is correctly emitted, but is confusing, for `min_const_generics`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants