rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
13.62k stars 1.49k forks source link

fix: keep parentheses when the precedence of inner expr is lower than the outer one #17187

Closed roife closed 6 days ago

roife commented 1 week ago

fix #17185

Additionally, this PR simplifies some code in apply_demorgan.

roife commented 1 week ago

Besides, I'm not sure about the commented-out test:

https://github.com/rust-lang/rust-analyzer/blob/ef5c6daf6ec0797c0e4c3b323853390f15078e70/crates/ide-assists/src/handlers/apply_demorgan.rs#L222-L231

1 || 3 &&$0 4 || 5 should be transformed into 1 || !(!3 || !4) || 5 (just as the assist does currently) instead of !(!1 || !3 || !4) || 5. Perhaps we should update the test and uncomment it.

alibektas commented 1 week ago

Besides, I'm not sure about the commented-out test:

https://github.com/rust-lang/rust-analyzer/blob/ef5c6daf6ec0797c0e4c3b323853390f15078e70/crates/ide-assists/src/handlers/apply_demorgan.rs#L222-L231

1 || 3 &&$0 4 || 5 should be transformed into 1 || !(!3 || !4) || 5 (just as the assist does currently) instead of !(!1 || !3 || !4) || 5. Perhaps we should update the test and uncomment it.

Yes we can do definitely do that.

Veykril commented 6 days ago

Thanks! @bors r+

bors commented 6 days ago

:pushpin: Commit 4ada8265e67cd647ebbbe6f590085e688d4385e7 has been approved by Veykril

It is now in the queue for this repository.

bors commented 6 days ago

:hourglass: Testing commit 4ada8265e67cd647ebbbe6f590085e688d4385e7 with merge 7aecf1ae35f3fcc8e0fcde8abbfe807cc098e4e8...

bors commented 6 days ago

:sunny: Test successful - checks-actions Approved by: Veykril Pushing 7aecf1ae35f3fcc8e0fcde8abbfe807cc098e4e8 to master...