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.
This commit is contained in:
Michael Goulet 2024-03-20 16:53:50 -04:00
parent 8f62a2dedb
commit f670f3b5e0

View File

@ -55,9 +55,10 @@ fn is_short_pattern_inner(pat: &ast::Pat) -> bool {
ast::PatKind::TupleStruct(_, ref path, ref subpats) => { ast::PatKind::TupleStruct(_, ref path, ref subpats) => {
path.segments.len() <= 1 && subpats.len() <= 1 path.segments.len() <= 1 && subpats.len() <= 1
} }
ast::PatKind::Box(ref p) | ast::PatKind::Ref(ref p, _) | ast::PatKind::Paren(ref p) => { ast::PatKind::Box(ref p)
is_short_pattern_inner(&*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)), PatKind::Or(ref pats) => pats.iter().all(|p| is_short_pattern_inner(p)),
} }
} }
@ -277,6 +278,7 @@ fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String>
.rewrite(context, shape.offset_left(1)?.sub_width(1)?) .rewrite(context, shape.offset_left(1)?.sub_width(1)?)
.map(|inner_pat| format!("({})", inner_pat)), .map(|inner_pat| format!("({})", inner_pat)),
PatKind::Err(_) => None, PatKind::Err(_) => None,
PatKind::Deref(_) => None,
} }
} }
} }