-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Format tokio::select! with rustfmt #5441
Comments
Although this would be very nice, we cannot change the syntax used by the macro. |
I'm going to close this. As it currently stands, this is not actionable for us. Feel free to reopen or open a new issue if a change in rustfmt makes this possible in the future. |
The best workaround is probably to move the branch code into a standalone function, and call it from the macro. That way, the function can be formatted. |
I'm not sure I understand your suggestion. |
The problem is that in this example: tokio::select! {
val = rx1 => {
println!("rx1 completed first with {:?}", val);
// do some other stuff with rx1
}
val = rx2 => {
println!("rx2 completed first with {:?}", val);
// do some other stuff with rx2
}
} ...the code in the branches is not formatted by rustfmt, because it is inside the By moving the code into separate functions outside the macro: tokio::select! {
val = rx1 => {
println!("rx1 completed first with {:?}", val);
handle_rx1(val)
}
val = rx2 => {
println!("rx2 completed first with {:?}", val);
handle_rx2(val)
}
}
fn handle_rx1(val: ...): void {
// do some stuff with rx1
}
fn handle_rx2(val: ...): void {
// do some stuff with rx2
} ...the functions can be formatted correctly. |
I found that a decent solution is to put |
Is your feature request related to a problem? Please describe.
The
tokio::select!
macro is something used quite often in real-world code. However, rustfmt cannot format code inside that call.Describe the solution you'd like
Maybe it would be possible to adjust the macro so that the code can be formatted with rustfmt?
I found a project here which plays with alternative syntax to enable this. (Pinging @jkelleyrtp)
Describe alternatives you've considered
Alternatively, maybe rustfmt could be changed to support the current syntax? Not sure if that's possible, since macros can have quite diverse syntax.
Related issue: rust-lang/rustfmt#8
The text was updated successfully, but these errors were encountered: