Skip to content

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

Closed
@matthiaskrgr

Description

@matthiaskrgr

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-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