Closed
Description
The intention of the second arm of the match below is to match slices with one element only (in this case only the second element in vects should match).
let vects= [&[1u, 2, 3], &[1], &[]];
for &vec in vects.iter() {
let msg= match vec {
[] => format!("empty"),
[a] => format!("only one element: {}", a),
[a, ..rest] => format!("many elements, first is {}, then there are {}", a, rest) // this is unreachable?
};
However the compiler complains that the third arm is now unreachable.
The workaround is transforming the second arm in [a,..rest] if rest==[]
but I was advised on the #rust IRC channel that the [a]
should work and that this is a bug.
Metadata
Metadata
Assignees
Labels
No labels