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

Error for chained less-than/greater-than comparisons misleading. #65659

Closed
vext01 opened this issue Oct 21, 2019 · 0 comments · Fixed by #68108
Closed

Error for chained less-than/greater-than comparisons misleading. #65659

vext01 opened this issue Oct 21, 2019 · 0 comments · Fixed by #68108
Labels
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. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@vext01
Copy link
Contributor

vext01 commented Oct 21, 2019

Hi,

As I understand, chaining inequality operators like <, >, <= and >= is not allowed. Yet trying to do so will ask you to add parenthesies:

fn main() {
    let x = 2;
    
    if 1 <= x <= 3 {
        println!("yes");
    } else {
        println!("no");
    }
}

Gives:

error: chained comparison operators require parentheses
 --> src/main.rs:4:10
  |
4 |     if 1 <= x <= 3 {
  |          ^^^^^^^

error[E0308]: mismatched types
 --> src/main.rs:4:18
  |
4 |     if 1 <= x <= 3 {
  |                  ^ expected bool, found integer
  |
  = note: expected type `bool`
             found type `{integer}`

The first error is false advice in the context of <=. It would have been ok for == though.

Thanks :)

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 21, 2019
@varkor varkor added the D-confusing Diagnostics: Confusing error or lint that should be reworked. label Oct 21, 2019
@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Dec 8, 2019
Centril added a commit to Centril/rust that referenced this issue Jan 11, 2020
…ns, r=Centril

Add suggestions when encountering chained comparisons

Ideally, we'd also prevent the type error, which is just extra noise, but that will require moving the error from the parser, and I think the suggestion makes things clear enough for now.

Fixes rust-lang#65659.
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jan 11, 2020
…ns, r=Centril

Add suggestions when encountering chained comparisons

Ideally, we'd also prevent the type error, which is just extra noise, but that will require moving the error from the parser, and I think the suggestion makes things clear enough for now.

Fixes rust-lang#65659.
@bors bors closed this as completed in 82c19b4 Jan 12, 2020
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 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. D-confusing Diagnostics: Confusing error or lint that should be reworked. 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.

4 participants