Parse a pattern with no arm
This commit is contained in:
parent
1ab7fc99af
commit
a445ba8a9d
@ -223,7 +223,7 @@ fn rewrite_match_arm(
|
|||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
let (missing_span, attrs_str) = if !arm.attrs.is_empty() {
|
let (missing_span, attrs_str) = if !arm.attrs.is_empty() {
|
||||||
if contains_skip(&arm.attrs) {
|
if contains_skip(&arm.attrs) {
|
||||||
let (_, body) = flatten_arm_body(context, &arm.body, None);
|
let (_, body) = flatten_arm_body(context, arm.body.as_deref()?, None);
|
||||||
// `arm.span()` does not include trailing comma, add it manually.
|
// `arm.span()` does not include trailing comma, add it manually.
|
||||||
return Some(format!(
|
return Some(format!(
|
||||||
"{}{}",
|
"{}{}",
|
||||||
@ -246,7 +246,7 @@ fn rewrite_match_arm(
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Patterns
|
// Patterns
|
||||||
let pat_shape = match &arm.body.kind {
|
let pat_shape = match &arm.body.as_ref()?.kind {
|
||||||
ast::ExprKind::Block(_, Some(label)) => {
|
ast::ExprKind::Block(_, Some(label)) => {
|
||||||
// Some block with a label ` => 'label: {`
|
// Some block with a label ` => 'label: {`
|
||||||
// 7 = ` => : {`
|
// 7 = ` => : {`
|
||||||
@ -280,10 +280,10 @@ fn rewrite_match_arm(
|
|||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let arrow_span = mk_sp(arm.pat.span.hi(), arm.body.span().lo());
|
let arrow_span = mk_sp(arm.pat.span.hi(), arm.body.as_ref()?.span().lo());
|
||||||
rewrite_match_body(
|
rewrite_match_body(
|
||||||
context,
|
context,
|
||||||
&arm.body,
|
arm.body.as_ref()?,
|
||||||
&lhs_str,
|
&lhs_str,
|
||||||
shape,
|
shape,
|
||||||
guard_str.contains('\n'),
|
guard_str.contains('\n'),
|
||||||
|
@ -97,7 +97,12 @@ impl Spanned for ast::Arm {
|
|||||||
} else {
|
} else {
|
||||||
self.attrs[0].span.lo()
|
self.attrs[0].span.lo()
|
||||||
};
|
};
|
||||||
span_with_attrs_lo_hi!(self, lo, self.body.span.hi())
|
let hi = if let Some(body) = &self.body {
|
||||||
|
body.span.hi()
|
||||||
|
} else {
|
||||||
|
self.pat.span.hi()
|
||||||
|
};
|
||||||
|
span_with_attrs_lo_hi!(self, lo, hi)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user