]> git.lizzy.rs Git - rust.git/commitdiff
parser: call .struct_span_err directly
authorMazdak Farrokhzad <twingoow@gmail.com>
Mon, 30 Dec 2019 13:56:57 +0000 (14:56 +0100)
committerMazdak Farrokhzad <twingoow@gmail.com>
Tue, 31 Dec 2019 03:33:34 +0000 (04:33 +0100)
src/librustc_parse/parser/attr.rs
src/librustc_parse/parser/diagnostics.rs
src/librustc_parse/parser/expr.rs
src/librustc_parse/parser/item.rs
src/librustc_parse/parser/module.rs
src/librustc_parse/parser/pat.rs
src/librustc_parse/parser/path.rs

index 4b7f1e9a4d8338a8ccfd3f874c6ed320e0458fa8..d26677a6c32c0ea604bef6177f43bed7f71bbabb 100644 (file)
@@ -133,7 +133,7 @@ fn parse_attribute_with_inner_parse_policy(
                             "previous outer attribute"
                         };
 
-                        let mut diagnostic = self.diagnostic().struct_span_err(attr_sp, reason);
+                        let mut diagnostic = self.struct_span_err(attr_sp, reason);
 
                         if let Some(prev_attr_sp) = prev_attr_sp {
                             diagnostic
@@ -231,8 +231,7 @@ pub fn parse_attr_item(&mut self) -> PResult<'a, ast::AttrItem> {
 
         if !lit.kind.is_unsuffixed() {
             let msg = "suffixed literals are not allowed in attributes";
-            self.diagnostic()
-                .struct_span_err(lit.span, msg)
+            self.struct_span_err(lit.span, msg)
                 .help(
                     "instead of using a suffixed literal \
                                     (1u8, 1.0f32, etc.), use an unsuffixed version \
@@ -332,6 +331,6 @@ fn parse_meta_item_inner(&mut self) -> PResult<'a, ast::NestedMetaItem> {
 
         let found = pprust::token_to_string(&self.token);
         let msg = format!("expected unsuffixed literal or identifier, found `{}`", found);
-        Err(self.diagnostic().struct_span_err(self.token.span, &msg))
+        Err(self.struct_span_err(self.token.span, &msg))
     }
 }
index 578f816be58c8f58ad79fcabc2b19b5df64e01fe..d091cceb932fc2fc917da61df79f99a887c9ae88 100644 (file)
@@ -502,18 +502,17 @@ pub(super) fn check_trailing_angle_brackets(&mut self, segment: &PathSegment, en
             let span = lo.until(self.token.span);
 
             let total_num_of_gt = number_of_gt + number_of_shr * 2;
-            self.diagnostic()
-                .struct_span_err(
-                    span,
-                    &format!("unmatched angle bracket{}", pluralize!(total_num_of_gt)),
-                )
-                .span_suggestion(
-                    span,
-                    &format!("remove extra angle bracket{}", pluralize!(total_num_of_gt)),
-                    String::new(),
-                    Applicability::MachineApplicable,
-                )
-                .emit();
+            self.struct_span_err(
+                span,
+                &format!("unmatched angle bracket{}", pluralize!(total_num_of_gt)),
+            )
+            .span_suggestion(
+                span,
+                &format!("remove extra angle bracket{}", pluralize!(total_num_of_gt)),
+                String::new(),
+                Applicability::MachineApplicable,
+            )
+            .emit();
         }
     }
 
@@ -762,8 +761,7 @@ pub(super) fn maybe_recover_from_bad_qpath_stage_2<T: RecoverQPath>(
         path.span = ty_span.to(self.prev_span);
 
         let ty_str = self.span_to_snippet(ty_span).unwrap_or_else(|_| pprust::ty_to_string(&ty));
-        self.diagnostic()
-            .struct_span_err(path.span, "missing angle brackets in associated item path")
+        self.struct_span_err(path.span, "missing angle brackets in associated item path")
             .span_suggestion(
                 // This is a best-effort recovery.
                 path.span,
index b51a4465b159e47fc1a1f04a7586788a591b8598..5566407963a5bb2fa1832c02574cf640678cc712 100644 (file)
@@ -1915,8 +1915,7 @@ fn error_on_eq_field_init(&self, field_name: Ident) {
             return;
         }
 
-        self.diagnostic()
-            .struct_span_err(self.token.span, "expected `:`, found `=`")
+        self.struct_span_err(self.token.span, "expected `:`, found `=`")
             .span_suggestion(
                 field_name.span.shrink_to_hi().to(self.token.span),
                 "replace equals symbol with a colon",
index 343c6667d47d595d294a4a30467d1a42ffc08ac8..424483292b66ead1a52fe0e8f91f7bec1d500fa7 100644 (file)
@@ -306,8 +306,7 @@ fn parse_item_implementation(
                 // possible public struct definition where `struct` was forgotten
                 let ident = self.parse_ident().unwrap();
                 let msg = format!("add `struct` here to parse `{}` as a public struct", ident);
-                let mut err =
-                    self.diagnostic().struct_span_err(sp, "missing `struct` for struct definition");
+                let mut err = self.struct_span_err(sp, "missing `struct` for struct definition");
                 err.span_suggestion_short(
                     sp,
                     &msg,
@@ -335,7 +334,7 @@ fn parse_item_implementation(
                 };
 
                 let msg = format!("missing `{}` for {} definition", kw, kw_name);
-                let mut err = self.diagnostic().struct_span_err(sp, &msg);
+                let mut err = self.struct_span_err(sp, &msg);
                 if !ambiguous {
                     self.consume_block(token::Brace, ConsumeClosingDelim::Yes);
                     let suggestion =
@@ -375,7 +374,7 @@ fn parse_item_implementation(
                     ("fn` or `struct", "function or struct", true)
                 };
                 let msg = format!("missing `{}` for {} definition", kw, kw_name);
-                let mut err = self.diagnostic().struct_span_err(sp, &msg);
+                let mut err = self.struct_span_err(sp, &msg);
                 if !ambiguous {
                     err.span_suggestion_short(
                         sp,
@@ -466,7 +465,7 @@ fn expected_item_err(&mut self, attrs: &[Attribute]) -> PResult<'a, ()> {
             _ => "expected item after attributes",
         };
 
-        let mut err = self.diagnostic().struct_span_err(self.prev_span, message);
+        let mut err = self.struct_span_err(self.prev_span, message);
         if attrs.last().unwrap().is_doc_comment() {
             err.span_label(self.prev_span, "this doc comment doesn't document anything");
         }
@@ -536,7 +535,6 @@ fn missing_assoc_item_kind_err(
         //        ^^ `sp` below will point to this
         let sp = prev_span.between(self.prev_span);
         let mut err = self
-            .diagnostic()
             .struct_span_err(sp, &format!("{} for {}-item declaration", expected_kinds, item_type));
         err.span_label(sp, expected_kinds);
         err
@@ -1603,9 +1601,8 @@ fn complain_if_pub_macro(&self, vis: &VisibilityKind, sp: Span) {
             VisibilityKind::Inherited => {}
             _ => {
                 let mut err = if self.token.is_keyword(sym::macro_rules) {
-                    let mut err = self
-                        .diagnostic()
-                        .struct_span_err(sp, "can't qualify macro_rules invocation with `pub`");
+                    let mut err =
+                        self.struct_span_err(sp, "can't qualify macro_rules invocation with `pub`");
                     err.span_suggestion(
                         sp,
                         "try exporting the macro",
@@ -1614,9 +1611,8 @@ fn complain_if_pub_macro(&self, vis: &VisibilityKind, sp: Span) {
                     );
                     err
                 } else {
-                    let mut err = self
-                        .diagnostic()
-                        .struct_span_err(sp, "can't qualify macro invocation with `pub`");
+                    let mut err =
+                        self.struct_span_err(sp, "can't qualify macro invocation with `pub`");
                     err.help("try adjusting the macro to put `pub` inside the invocation");
                     err
                 };
index 3f54e0b6de031f7922368433a62760b50a415a32..7f5104d260d6aaeff96a13fcd1be84e678c4c4a5 100644 (file)
@@ -129,7 +129,7 @@ fn submod_path(
             DirectoryOwnership::UnownedViaBlock => {
                 let msg = "Cannot declare a non-inline module inside a block \
                     unless it has a path attribute";
-                let mut err = self.diagnostic().struct_span_err(id_sp, msg);
+                let mut err = self.struct_span_err(id_sp, msg);
                 if paths.path_exists {
                     let msg = format!(
                         "Maybe `use` the module `{}` instead of redeclaring it",
@@ -140,9 +140,8 @@ fn submod_path(
                 Err(err)
             }
             DirectoryOwnership::UnownedViaMod => {
-                let mut err = self
-                    .diagnostic()
-                    .struct_span_err(id_sp, "cannot declare a new module at this location");
+                let mut err =
+                    self.struct_span_err(id_sp, "cannot declare a new module at this location");
                 if !id_sp.is_dummy() {
                     let src_path = self.sess.source_map().span_to_filename(id_sp);
                     if let FileName::Real(src_path) = src_path {
index d2288b27a0c40a775c6d229177ef58668fba6116..6a98d29675e735980a220065a54d6c71ea3ef4a4 100644 (file)
@@ -699,8 +699,7 @@ fn parse_pat_range_to(&mut self, re: RangeEnd, form: &str) -> PResult<'a, PatKin
         let range_span = lo.to(end.span);
         let begin = self.mk_expr(range_span, ExprKind::Err, AttrVec::new());
 
-        self.diagnostic()
-            .struct_span_err(range_span, &format!("`{}X` range patterns are not supported", form))
+        self.struct_span_err(range_span, &format!("`{}X` range patterns are not supported", form))
             .span_suggestion(
                 range_span,
                 "try using the minimum value for the type",
@@ -722,18 +721,17 @@ fn parse_pat_range_end_opt(&mut self, begin: &Expr, form: &str) -> PResult<'a, P
             // Parsing e.g. `X..`.
             let range_span = begin.span.to(self.prev_span);
 
-            self.diagnostic()
-                .struct_span_err(
-                    range_span,
-                    &format!("`X{}` range patterns are not supported", form),
-                )
-                .span_suggestion(
-                    range_span,
-                    "try using the maximum value for the type",
-                    format!("{}{}MAX", pprust::expr_to_string(&begin), form),
-                    Applicability::HasPlaceholders,
-                )
-                .emit();
+            self.struct_span_err(
+                range_span,
+                &format!("`X{}` range patterns are not supported", form),
+            )
+            .span_suggestion(
+                range_span,
+                "try using the maximum value for the type",
+                format!("{}{}MAX", pprust::expr_to_string(&begin), form),
+                Applicability::HasPlaceholders,
+            )
+            .emit();
 
             Ok(self.mk_expr(range_span, ExprKind::Err, AttrVec::new()))
         }
index e6c7d50fb4cf676a0f8a7088decc1a78083c7af3..ef22628a5e06da6d9ecf1581634a6f5a9924cf72 100644 (file)
@@ -325,24 +325,23 @@ fn parse_generic_args_with_leading_angle_bracket_recovery(
 
                 // Make a span over ${unmatched angle bracket count} characters.
                 let span = lo.with_hi(lo.lo() + BytePos(snapshot.unmatched_angle_bracket_count));
-                self.diagnostic()
-                    .struct_span_err(
-                        span,
-                        &format!(
-                            "unmatched angle bracket{}",
-                            pluralize!(snapshot.unmatched_angle_bracket_count)
-                        ),
-                    )
-                    .span_suggestion(
-                        span,
-                        &format!(
-                            "remove extra angle bracket{}",
-                            pluralize!(snapshot.unmatched_angle_bracket_count)
-                        ),
-                        String::new(),
-                        Applicability::MachineApplicable,
-                    )
-                    .emit();
+                self.struct_span_err(
+                    span,
+                    &format!(
+                        "unmatched angle bracket{}",
+                        pluralize!(snapshot.unmatched_angle_bracket_count)
+                    ),
+                )
+                .span_suggestion(
+                    span,
+                    &format!(
+                        "remove extra angle bracket{}",
+                        pluralize!(snapshot.unmatched_angle_bracket_count)
+                    ),
+                    String::new(),
+                    Applicability::MachineApplicable,
+                )
+                .emit();
 
                 // Try again without unmatched angle bracket characters.
                 self.parse_generic_args()