Fix checking if newline is needed before else in let-else statement#5902
Conversation
|
@rhysd I haven't had a chance to review this yet, but I wanted to see how your changes handle this case: fn issue5901() {
#[cfg(target_os = "linux")]
// some comment between attr and let-else
let Some(x) = foo() else { return; };
}
fn issue5901() {
#[cfg(target_os = "linux")]
/* some comment between attr and let-else */
let Some(x) = foo() else { return; };
} |
|
Thank you for the point. I'll try to add new test. |
|
I confirmed that this fix didn't work for the comment between the attributes and let-else statement. I'll have a look whether it can be fixed. fn main() {
#[cfg(target_os = "linux")]
// this is test
- let x = 42 else { todo!() };
+ let x = 42
+ else {
+ todo!()
+ };
} |
|
@rhysd thanks for taking a look 🙏🏼. Before you keep working on this I also want to point out that any change needs to be version gated since let-else support was released as stable and we can't break our formatting guarantees. |
|
@ytmimi Thanks for the information. I'll check the documentation. And I may find a way to strip things before |
|
@ytmimi I force-pushed the fix. I added more tests and v1 version gate as well. Is there any place to add tests for v1 formatting? Currently only v2 formatting is tested. Please let me know if I should create some test case like |
|
You should create a |
ytmimi
left a comment
There was a problem hiding this comment.
Thanks again for taking the time to look into this. I think you're on the right track with getting the let_kw_offset early on. As mentioned, there are two other calls that use the result below for their calculations and those need to be changed as well.
|
@ytmimi Thank you for your review comments. I updated this branch to resolve them.
|
…space in let-else statement
|
@ytmimi Thank you for your review comments again. I addressed them.
|
ytmimi
left a comment
There was a problem hiding this comment.
Thanks for helping to fix this issue and for your first contribution to rustfmt 🥳
|
As a last step I want to run our diff-check job, It should pass since the changes are version gated, but I still want to go through this process. |
Fixes #5901