Skip to content

Commit

Permalink
Implement macro-based deref!() syntax for deref patterns
Browse files Browse the repository at this point in the history
Stop using `box PAT` syntax for deref patterns, as it's misleading and
also causes their semantics being tangled up.
  • Loading branch information
compiler-errors committed Mar 21, 2024
1 parent 8f62a2d commit f670f3b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ fn is_short_pattern_inner(pat: &ast::Pat) -> bool {
ast::PatKind::TupleStruct(_, ref path, ref subpats) => {
path.segments.len() <= 1 && subpats.len() <= 1
}
ast::PatKind::Box(ref p) | ast::PatKind::Ref(ref p, _) | ast::PatKind::Paren(ref p) => {
is_short_pattern_inner(&*p)
}
ast::PatKind::Box(ref p)
| PatKind::Deref(ref p)
| ast::PatKind::Ref(ref p, _)
| ast::PatKind::Paren(ref p) => is_short_pattern_inner(&*p),
PatKind::Or(ref pats) => pats.iter().all(|p| is_short_pattern_inner(p)),
}
}
Expand Down Expand Up @@ -277,6 +278,7 @@ impl Rewrite for Pat {
.rewrite(context, shape.offset_left(1)?.sub_width(1)?)
.map(|inner_pat| format!("({})", inner_pat)),
PatKind::Err(_) => None,
PatKind::Deref(_) => None,
}
}
}
Expand Down

0 comments on commit f670f3b

Please sign in to comment.