about summary refs log tree commit diff
path: root/src/librustc_parse/parser
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-12-04 04:24:53 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2019-12-23 13:34:06 +0100
commit66b8ae4bce061907bb1fdb88ba6f0a9ad918c378 (patch)
treefe801655a3493ca891e51ac97f5cf75d23a942a3 /src/librustc_parse/parser
parent701b974eb9df59de29a0cff86a2b6a9026e31b5a (diff)
downloadrust-66b8ae4bce061907bb1fdb88ba6f0a9ad918c378.tar.gz
rust-66b8ae4bce061907bb1fdb88ba6f0a9ad918c378.zip
extract error_struct_lit_not_allowed_here
Diffstat (limited to 'src/librustc_parse/parser')
-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,