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

nonminimal_bool is very hard to read #5045

Closed
jyn514 opened this issue Jan 12, 2020 · 8 comments · Fixed by #5046
Closed

nonminimal_bool is very hard to read #5045

jyn514 opened this issue Jan 12, 2020 · 8 comments · Fixed by #5046
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages L-complexity Lint: Belongs in the complexity lint group

Comments

@jyn514
Copy link
Member

jyn514 commented Jan 12, 2020

warning: this boolean expression can be simplified
  --> crates/ra_parser/src/grammar/items.rs:24:11
   |
24 |     while !p.at(EOF) && !(stop_on_r_curly && p.at(T!['}'])) {
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `!(stop_on_r_curly && p.at(T!['}']) || p.at(EOF))`

b || a is not the same as !a && b.

@jyn514 jyn514 changed the title nominimal_bool is wrong nonminimal_bool is wrong Jan 12, 2020
@mati865
Copy link
Contributor

mati865 commented Jan 12, 2020

@jyn514
Copy link
Member Author

jyn514 commented Jan 12, 2020

Oh I misread the change: I thought it was !(stop_on_r_curly && p.at(T!['}'])) || p.at(EOF) but it was actually !(stop_on_r_curly && p.at(T!['}']) || p.at(EOF)).

@jyn514 jyn514 changed the title nonminimal_bool is wrong nonminimal_bool is very hard to read Jan 12, 2020
@JohnTitor
Copy link
Member

Hm, indeed the suggestion is hard a bit to read but it depends on the complexity of the original code. What we should do here?

@jyn514
Copy link
Member Author

jyn514 commented Jan 13, 2020

A good start would be to keep the original order of the conditions: if it were !(p.at(EOF) || stop_on_r_curly && p.at(T!['}'])) I think I would have noticed the difference.

@jyn514
Copy link
Member Author

jyn514 commented Jan 13, 2020

That order also reads nicer to my eye, although it might just be because I'm familiar with the code.

@JohnTitor
Copy link
Member

Yeah, I agree with not to change the ordering, at least this case.

@JohnTitor JohnTitor added L-complexity Lint: Belongs in the complexity lint group C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Jan 13, 2020
@JohnTitor
Copy link
Member

Heh, I found this comment btw:

// nonminimal_bool can produce minimal but
// not human readable expressions (#3141)

@JohnTitor
Copy link
Member

So, let's deal with the order problem only here, others should be tracked in #3141.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages L-complexity Lint: Belongs in the complexity lint group
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants