Skip to content

Commit 66b8ae4

Browse files
committed
extract error_struct_lit_not_allowed_here
1 parent 701b974 commit 66b8ae4

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/librustc_parse/parser/expr.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,22 +1747,23 @@ impl<'a> Parser<'a> {
17471747
// This is a struct literal, but we don't can't accept them here.
17481748
let expr = self.parse_struct_expr(lo, path.clone(), attrs.clone());
17491749
if let (Ok(expr), false) = (&expr, struct_allowed) {
1750-
self.struct_span_err(expr.span, "struct literals are not allowed here")
1751-
.multipart_suggestion(
1752-
"surround the struct literal with parentheses",
1753-
vec![
1754-
(lo.shrink_to_lo(), "(".to_string()),
1755-
(expr.span.shrink_to_hi(), ")".to_string()),
1756-
],
1757-
Applicability::MachineApplicable,
1758-
)
1759-
.emit();
1750+
self.error_struct_lit_not_allowed_here(lo, expr.span);
17601751
}
17611752
return Some(expr);
17621753
}
17631754
None
17641755
}
17651756

1757+
fn error_struct_lit_not_allowed_here(&self, lo: Span, sp: Span) {
1758+
self.struct_span_err(sp, "struct literals are not allowed here")
1759+
.multipart_suggestion(
1760+
"surround the struct literal with parentheses",
1761+
vec![(lo.shrink_to_lo(), "(".to_string()), (sp.shrink_to_hi(), ")".to_string())],
1762+
Applicability::MachineApplicable,
1763+
)
1764+
.emit();
1765+
}
1766+
17661767
pub(super) fn parse_struct_expr(
17671768
&mut self,
17681769
lo: Span,

0 commit comments

Comments
 (0)