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
I have 2 code pieces, one where rustfmt removes curly braces and one where it does not and it annoys me.
It may be of no consequences, but I still fill confused by it especially because the output seems less readable to me.
First example where rustfmt does not remove curly braces
use std::thread;use std::time::Duration;fnmain(){let handle = thread::spawn(|| {for i in1..10{println!("hi number {} from the spawned thread!", i);
thread::sleep(Duration::from_millis(1));}});for i in1..5{println!("hi number {} from the main thread!", i);
thread::sleep(Duration::from_millis(1));}
handle.join().unwrap();}
Here is the second code before use of rustfmt:
use std::thread;use std::time::Duration;fnmain(){let handle = thread::spawn(|| {loop{println!("hi from the spawned thread!");
thread::sleep(Duration::from_millis(1));}});for i in1..5{println!("hi number {} from the main thread!", i);
thread::sleep(Duration::from_millis(1));}
handle.join().unwrap();}
And now the code after rustfmt pass (the loop statement changes):
use std::thread;use std::time::Duration;fnmain(){let handle = thread::spawn(|| loop{println!("hi from the spawned thread!");
thread::sleep(Duration::from_millis(1));});for i in1..5{println!("hi number {} from the main thread!", i);
thread::sleep(Duration::from_millis(1));}
handle.join().unwrap();}
I like the fact that the closure is presented in its own block even if its only a loop block.
Furthermore, I very hate that a tool is removing some code even if it is unnecessary braces. I would prefer suggestions for that.
I would love to configure rustfmt to not remove code at all and just work on indentation. Is there an option for that ?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have 2 code pieces, one where rustfmt removes curly braces and one where it does not and it annoys me.
It may be of no consequences, but I still fill confused by it especially because the output seems less readable to me.
First example where rustfmt does not remove curly braces
Here is the second code before use of rustfmt:
And now the code after rustfmt pass (the loop statement changes):
I like the fact that the closure is presented in its own block even if its only a loop block.
Furthermore, I very hate that a tool is removing some code even if it is unnecessary braces. I would prefer suggestions for that.
I would love to configure rustfmt to not remove code at all and just work on indentation. Is there an option for that ?
Beta Was this translation helpful? Give feedback.
All reactions