patterns: make PatOp::ArRep match Op::ArRep

This commit is contained in:
2025-12-16 04:17:38 -05:00
parent 1887c9c014
commit cca8347cc2
3 changed files with 4 additions and 4 deletions

View File

@@ -282,7 +282,7 @@ pub enum PatOp {
/// Matches the elements of a slice or array
Slice,
/// Matches a constant-size slice with repeating elements
Arrep,
ArRep,
/// Matches a type annotation or struct member
Typed,
/// Matches a function signature

View File

@@ -259,7 +259,7 @@ impl Display for Pat {
Self::NamedTuple(name, bind) => write!(f, "{name} {bind}"),
Self::Op(PatOp::Tuple, pats) => f.delimit("(", ")").list(pats, ", "),
Self::Op(PatOp::Slice, pats) => f.delimit("[", "]").list(pats, ", "),
Self::Op(op @ PatOp::Arrep, pats) => f.delimit("[", "]").list(pats, op),
Self::Op(op @ PatOp::ArRep, pats) => f.delimit("[", "]").list(pats, op),
Self::Op(op @ (PatOp::Typed | PatOp::Fn), pats) => f.list(pats, op),
Self::Op(op @ PatOp::Alt, pats) => f.delimit("<", ">").list(pats, op),
Self::Op(op, pats) => match pats.as_slice() {
@@ -283,7 +283,7 @@ impl Display for PatOp {
Self::RangeIn => "..=",
Self::Tuple => ", ",
Self::Slice => ", ",
Self::Arrep => "; ",
Self::ArRep => "[;]",
Self::Typed => ": ",
Self::Fn => " -> ",
Self::Alt => " | ",

View File

@@ -174,7 +174,7 @@ fn parse_array_pat(p: &mut Parser<'_>) -> PResult<Pat> {
p.expect(TKind::RBrack)?;
Ok(match (repeat, item) {
(Some(repeat), item) => Pat::Op(PatOp::Arrep, vec![item, repeat]),
(Some(repeat), item) => Pat::Op(PatOp::ArRep, vec![item, repeat]),
(None, Pat::Op(PatOp::Tuple, items)) => Pat::Op(PatOp::Slice, items),
(None, item) => Pat::Op(PatOp::Slice, vec![item]),
})