Skip to content

better syntax error for "not <condition>" instead "!<condition>" #46836

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

Closed
matthiaskrgr opened this issue Dec 19, 2017 · 0 comments
Closed

better syntax error for "not <condition>" instead "!<condition>" #46836

matthiaskrgr opened this issue Dec 19, 2017 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

this code

fn main() {
    funfunction(true);
}

fn funfunction(var: bool) {
    if not var  { println!("blubb");  }
}

currently emmits

  error: expected one of `,` or `}`, found `!`
 --> src/main.rs:6:26
  |
6 |     if not var  { println!("blubb");  }
  |                          ^ expected one of `,` or `}` here

error: expected `{`, found `var`
 --> src/main.rs:6:12
  |
6 |     if not var  { println!("blubb");  }
  |            ^^^-------------------------
  |            |
  |            help: try placing this code inside a block: `{ var{println,}; }`

error: aborting due to 2 previous errors

error: Could not compile `not`.

To learn more, run the command again with --verbose.

Could we detect explicitly if there are 2 unchained (via && or ||) "variables" after an "if" and if the first one is "not" and explicitly suggest using "!" instead of "not" instead?

meta:

rustc 1.24.0-nightly (dc39c3169 2017-12-17)
binary: rustc
commit-hash: dc39c31699a83313edf2ac096d0bf3cef871b705
commit-date: 2017-12-17
host: x86_64-unknown-linux-gnu
release: 1.24.0-nightly
LLVM version: 4.0
@Manishearth Manishearth added the A-diagnostics Area: Messages for errors, warnings, and lints label Dec 22, 2017
zackmdavis added a commit to zackmdavis/rust that referenced this issue Mar 8, 2018
Impressing confused Python users with magical diagnostics is probably
worth this very slight (only 25ish lines) extra complexity in the
parser?

FIXME comments have been left to note that the formatting after
autofixing the suggestion (with `rustfix` or an RLS-powered IDE) won't
be optimal. (It doesn't look like any of the existing `CodeMap` methods
make it easy to adjust the span.)

Resolves rust-lang#46836.
@jkordish jkordish added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 21, 2018
zackmdavis added a commit to zackmdavis/rust that referenced this issue Apr 9, 2018
Thanks to the inestimably inimitable Esteban "Estebank" Küber for
pointing this out.

This is relevant to rust-lang#46836.
@bors bors closed this as completed in ba0dd8e Apr 10, 2018
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 C-enhancement Category: An issue proposing an enhancement or a PR with one. 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