Arm split across lines
ErrorSafe fixA line in a match that starts with |, => or a guard's if, while the arm above still lacks its => and body, continues that arm from the wrong place.
Why
A line break ends an arm, as it ends a statement, unless the arm is plainly unfinished. An arm continues onto the next line when its line ends with |, => or an operator:
Red | Amber => true
A line that starts with |, => or a guard's if is the same arm written the other way round. The parser reads the line above as a pattern that never reached its =>, and so reports this error, since | Amber on a line of its own would otherwise look like an arm that starts with |. The fix joins the line to the one above. When a comment lies between them, joining would put the rest of the arm inside the comment, so the report has no fix.
After a complete arm, a line that starts with |, => or if is not this error: it is read as a new arm and reports a missing pattern.
Broken
enum Light {
Red
Amber
Green
}
fn stop(l: Light) -> bool {
match l {
Red
| Amber => true
Green => false
}
}
fn main() {
for l in [Light.Red, Light.Amber, Light.Green] {
print(stop(l))
}
}
What sisu says
error[E0133]: an arm continues on the line above --> E0133.sisu:10:9 | 10 | | Amber => true | ^ | help: join it to the line above | 9 | Red | Amber => true | + sisu: 1 error sisu: for more on a code, run `sisu explain <code>`: E0133
Fixed
enum Light {
Red
Amber
Green
}
fn stop(l: Light) -> bool {
match l {
Red | Amber => true
Green => false
}
}
fn main() {
for l in [Light.Red, Light.Amber, Light.Green] {
print(stop(l))
}
}
Sisu