jinxdash / prettier-plugin-rust

Prettier Rust is an opinionated code formatter that autocorrects bad syntax.
MIT License
178 stars 7 forks source link

The issue of semicolons affecting the lifecycle #22

Closed naqunmiemie closed 1 year ago

naqunmiemie commented 1 year ago

Input code

if let Some(left) = node.borrow().left.as_ref() {
                    deque.push_back(left.clone());
                };
                if let Some(right) = node.borrow().right.as_ref() {
                    deque.push_back(right.clone());
                };

Output code

if let Some(left) = node.borrow().left.as_ref() {
                    deque.push_back(left.clone());
                }
                if let Some(right) = node.borrow().right.as_ref() {
                    deque.push_back(right.clone());
                }

Additional context

image image

naqunmiemie commented 1 year ago

image

jinxdash commented 1 year ago

Related: https://github.com/rust-lang/rust/issues/70844

Per Rust spec those IfLet blocks are statements, hence semicolons should be meaningless and unnecessary.

My understanding is that this is a longstanding bug in the rust compiler whereby "if let" is syntax sugar that gets unrolled into some code that itself is missing a semicolon.

I'm inclined to say that the formatting is correct and that the issue is upstream. Maybe someone can correct me on that, otherwise I'd suggest adding // prettier-ignore above the if let blocks

naqunmiemie commented 1 year ago

image image I noticed that the last expression needed a semicolon

naqunmiemie commented 1 year ago

When the code is formatted, it doesn't compile properly. This may be unreasonable.