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

Extend invalid keyword usage help diagnostic #101627

Open
Rageking8 opened this issue Sep 9, 2022 · 2 comments
Open

Extend invalid keyword usage help diagnostic #101627

Rageking8 opened this issue Sep 9, 2022 · 2 comments
Labels
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.

Comments

@Rageking8
Copy link
Contributor

Given the following code: link

trait Trait { }

module test {
    pub constant X: i32 = 123;
    pub immutable Y: i32 = 234;
}

implement Trait for () { }

external "Rust" fn foo() { }

fn main() {
    let mutable a = 0;
}

The current output is:

   Compiling playground v0.0.1 (/playground)
error: expected one of `!` or `::`, found `test`
 --> src/main.rs:3:8
  |
3 | module test {
  |        ^^^^ expected one of `!` or `::`

error: could not compile `playground` due to previous error

There are multiple similar issues and all of them are merged (#99903 #99751 #100140). Hence, I think we should extend such behavior to all relevant rust keywords. Additional details are listed below:

  1. module -> mod
  2. constant -> const
  3. immutable -> const
  4. implement -> impl
  5. external -> extern
  6. mutable -> mut

Any of the wrong keywords on the lhs that is used in place of the right one on the rhs, should suggest changing said invalid keyword with the respective valid ones.

@Rageking8 Rageking8 added 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. labels Sep 9, 2022
@fmease
Copy link
Member

fmease commented Sep 10, 2022

Personally, I find this a bit excessive. I'd argue that it is very unlikely that anybody (be it an absolute beginner or a highly proficient long-term user) would accidentally write those suggested lengthy identifiers (“long versions”) instead of the actual keywords. Especially since all of these except extern are the most basic and most well-known keywords in Rust which are taught in the very beginning. Well, module could be an exception as well.

I don't want to discourage you from creating more GitHub issues related to parsing error recovery and syntax suggestions as the majority of them are really helpful, even for seasoned Rust programmers. I love the fact that if I mindlessly mistype something I am still greeted with excellent suggestions instead of random gibberish.

In my humble opinion however, we have to draw the line somewhere and for me this GitHub issue needlessly complicates the parser.

Just my two cents, no need to follow it.

@Rageking8
Copy link
Contributor Author

I understand that this may be a bit excessive, but I want the recovery to be slightly more uniform across the board. As mentioned above similar issues are already implemented and the above recovery suggestions are mostly keywords from other languages, which the user may have mistyped due to muscle memory coming from said language. In addition to extern and mod, mut may also be misspelled as mutable since that is a keyword in C++.

But, your suggestion is valid and I will try to minimize issues that are rare in occurrence. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

No branches or pull requests

2 participants