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

Add single line if block support for single expression #5939

Open
Sjael opened this issue Oct 11, 2023 · 1 comment · May be fixed by #6031
Open

Add single line if block support for single expression #5939

Sjael opened this issue Oct 11, 2023 · 1 comment · May be fixed by #6031

Comments

@Sjael
Copy link

Sjael commented Oct 11, 2023

What did you expect?

if false { continue }
let Some(x) = opt else { return };

What did you get?

if false { 
    continue  
}
let Some(x) = opt else { return };

cargo fmt puts let-else on a single line, and it could do the same to if blocks that have a single expression (i.e. return, break, or continue). That way there can be a consistent style for all guards.

@lukasjuhrich
Copy link

I hope piggybacking is okay, but I expected the same for if let: the line if let Some(r) = right { stack.push(*r) }, reaching column 53, will be broken even with --config use_small_heuristics=max.

@Sjael Sjael linked a pull request Jan 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants