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
The current style guide for match has some rather unfortunate consequences. rustfmt will turn
pat =>
very_long_expr,
pat =>
short_expr
into
pat =>
very_long_expr,
pat => short_expr
or turn
pat => {
stmt;
expr
}
pat => {
expr
}
into
pat => {
stmt;
expr
}
pat => expr
This can make a match that is entirely symmetric (every pattern and arm is of the same shape) look non-symmetric, making code harder to read since the reader cannot make use of the symmetry. Putting expr on the same line as pat can also make it easy to miss that there is any expression there at all.
A practical example of this looks as follows:
LocalValue::Dead => {// Lots of code here.}refmut local @ LocalValue::Live(Operand::Immediate(_))
| ref mut local @ LocalValue::Uninitialized => Ok(Ok(local)),LocalValue::SomeOtherVariant => {// Lots of code here.}
It is hard to even see the code for the final arm since it got put on the same line as the pattern, making it look like the two large code blocks are the only actual code here.
let kind = match rvalue {Rvalue::Ref(_, borrow_kind, _)if borrow_kind.allows_two_phase_borrow() =>
{RetagKind::TwoPhase}Rvalue::AddressOf(..) => RetagKind::Raw,
_ => RetagKind::Default,};
All match arms are just an enum constructor, but one of them gets curly braces forcibly added around it.
The text was updated successfully, but these errors were encountered:
The current style guide for
match
has some rather unfortunate consequences. rustfmt will turninto
or turn
into
This can make a match that is entirely symmetric (every pattern and arm is of the same shape) look non-symmetric, making code harder to read since the reader cannot make use of the symmetry. Putting
expr
on the same line aspat
can also make it easy to miss that there is any expression there at all.A practical example of this looks as follows:
It is hard to even see the code for the final arm since it got put on the same line as the pattern, making it look like the two large code blocks are the only actual code here.
All match arms are just an enum constructor, but one of them gets curly braces forcibly added around it.
The text was updated successfully, but these errors were encountered: