Skip to content

Commit 8480b31

Browse files
committed
extract recover_struct_comma_after_dotdot
1 parent e77b9d3 commit 8480b31

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/librustc_parse/parser/expr.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,21 +1788,7 @@ impl<'a> Parser<'a> {
17881788
self.recover_stmt();
17891789
}
17901790
}
1791-
if self.token == token::Comma {
1792-
self.struct_span_err(
1793-
exp_span.to(self.prev_span),
1794-
"cannot use a comma after the base struct",
1795-
)
1796-
.span_suggestion_short(
1797-
self.token.span,
1798-
"remove this comma",
1799-
String::new(),
1800-
Applicability::MachineApplicable,
1801-
)
1802-
.note("the base struct must always be the last field")
1803-
.emit();
1804-
self.recover_stmt();
1805-
}
1791+
self.recover_struct_comma_after_dotdot(exp_span);
18061792
break;
18071793
}
18081794

@@ -1864,6 +1850,22 @@ impl<'a> Parser<'a> {
18641850
return Ok(self.mk_expr(span, ExprKind::Struct(pth, fields, base), attrs));
18651851
}
18661852

1853+
fn recover_struct_comma_after_dotdot(&mut self, span: Span) {
1854+
if self.token != token::Comma {
1855+
return;
1856+
}
1857+
self.struct_span_err(span.to(self.prev_span), "cannot use a comma after the base struct")
1858+
.span_suggestion_short(
1859+
self.token.span,
1860+
"remove this comma",
1861+
String::new(),
1862+
Applicability::MachineApplicable,
1863+
)
1864+
.note("the base struct must always be the last field")
1865+
.emit();
1866+
self.recover_stmt();
1867+
}
1868+
18671869
/// Parses `ident (COLON expr)?`.
18681870
fn parse_field(&mut self) -> PResult<'a, Field> {
18691871
let attrs = self.parse_outer_attributes()?.into();

0 commit comments

Comments
 (0)