Skip to content

Commit f670f3b

Browse files
Implement macro-based deref!() syntax for deref patterns
Stop using `box PAT` syntax for deref patterns, as it's misleading and also causes their semantics being tangled up.
1 parent 8f62a2d commit f670f3b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/patterns.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ fn is_short_pattern_inner(pat: &ast::Pat) -> bool {
5555
ast::PatKind::TupleStruct(_, ref path, ref subpats) => {
5656
path.segments.len() <= 1 && subpats.len() <= 1
5757
}
58-
ast::PatKind::Box(ref p) | ast::PatKind::Ref(ref p, _) | ast::PatKind::Paren(ref p) => {
59-
is_short_pattern_inner(&*p)
60-
}
58+
ast::PatKind::Box(ref p)
59+
| PatKind::Deref(ref p)
60+
| ast::PatKind::Ref(ref p, _)
61+
| ast::PatKind::Paren(ref p) => is_short_pattern_inner(&*p),
6162
PatKind::Or(ref pats) => pats.iter().all(|p| is_short_pattern_inner(p)),
6263
}
6364
}
@@ -277,6 +278,7 @@ impl Rewrite for Pat {
277278
.rewrite(context, shape.offset_left(1)?.sub_width(1)?)
278279
.map(|inner_pat| format!("({})", inner_pat)),
279280
PatKind::Err(_) => None,
281+
PatKind::Deref(_) => None,
280282
}
281283
}
282284
}

0 commit comments

Comments
 (0)