about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_parse/parser/expr.rs21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs
index 5170a0b9d07..10912c84efc 100644
--- a/src/librustc_parse/parser/expr.rs
+++ b/src/librustc_parse/parser/expr.rs
@@ -1747,22 +1747,23 @@ impl<'a> Parser<'a> {
             // This is a struct literal, but we don't can't accept them here.
             let expr = self.parse_struct_expr(lo, path.clone(), attrs.clone());
             if let (Ok(expr), false) = (&expr, struct_allowed) {
-                self.struct_span_err(expr.span, "struct literals are not allowed here")
-                    .multipart_suggestion(
-                        "surround the struct literal with parentheses",
-                        vec![
-                            (lo.shrink_to_lo(), "(".to_string()),
-                            (expr.span.shrink_to_hi(), ")".to_string()),
-                        ],
-                        Applicability::MachineApplicable,
-                    )
-                    .emit();
+                self.error_struct_lit_not_allowed_here(lo, expr.span);
             }
             return Some(expr);
         }
         None
     }
 
+    fn error_struct_lit_not_allowed_here(&self, lo: Span, sp: Span) {
+        self.struct_span_err(sp, "struct literals are not allowed here")
+            .multipart_suggestion(
+                "surround the struct literal with parentheses",
+                vec![(lo.shrink_to_lo(), "(".to_string()), (sp.shrink_to_hi(), ")".to_string())],
+                Applicability::MachineApplicable,
+            )
+            .emit();
+    }
+
     pub(super) fn parse_struct_expr(
         &mut self,
         lo: Span,