You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if/else in closure with return type removes required curly brackets. This doesn't seem to be too uncommon to me but I didn't find any issues for this bug. Sorry if this is already known, if so please close this issue and refer to the original.
To Reproduce
fnmain(){let s:String = "ABAABBAA".chars().map(|c| -> char{if c == 'A'{'0'}else{'1'}}).collect();println!("{}", s);}
After running rustfmt on this code, it becomes
fnmain(){let s:String = "ABAABBAA".chars().map(|c| -> char if c == 'A'{'0'}else{'1'}).collect();println!("{}", s);}
This is no longer possible to compile and gives the following error:
error: expected `{`, found keyword `if`
--> src/main.rs:4:26
|
4 | .map(|c| -> char if c == 'A' { '0' } else { '1' })
| ^^------------------------------
| |
| expected `{`
| help: try placing this code inside a block: `{ if c == 'A' { '0' } else { '1' } }`
error: aborting due to previous error
The following example will not break the code:
fnmain(){let s:String = "ABAABBAA".chars().map(|c| -> char{if c == 'A'{return'0';}'1'}).collect();println!("{}", s);}
Describe the bug
if
/else
in closure with return type removes required curly brackets. This doesn't seem to be too uncommon to me but I didn't find any issues for this bug. Sorry if this is already known, if so please close this issue and refer to the original.To Reproduce
After running
rustfmt
on this code, it becomesThis is no longer possible to compile and gives the following error:
The following example will not break the code:
Expected behavior
The code to be formatted, but still working
Meta
rustup
rustftm <filename>
or via Rust vim pluginThe text was updated successfully, but these errors were encountered: