about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-01-10 18:03:53 +0000
committerbors <bors@rust-lang.org>2024-01-10 18:03:53 +0000
commita2d9d73e608f1b24eba840c4fd2d68dbe3b65e01 (patch)
tree42523e01769059455f89af632b53b841b1401d69 /compiler/rustc_parse/src/parser
parente9271846294c4ee5bd7706df68180320c0b5ff20 (diff)
parent700a3965202f4f403956fcce744ce5ba6adf2ddb (diff)
downloadrust-a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01.tar.gz
rust-a2d9d73e608f1b24eba840c4fd2d68dbe3b65e01.zip
Auto merge of #119751 - nnethercote:error-api-fixes, r=oli-obk
Diagnostic API fixes

Some improvements to diagnostic APIs: improve some naming, use shortcuts in more places, and add a couple of missing methods.

r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/attr.rs11
-rw-r--r--compiler/rustc_parse/src/parser/diagnostics.rs4
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs6
-rw-r--r--compiler/rustc_parse/src/parser/generics.rs2
-rw-r--r--compiler/rustc_parse/src/parser/item.rs26
-rw-r--r--compiler/rustc_parse/src/parser/mod.rs4
-rw-r--r--compiler/rustc_parse/src/parser/pat.rs2
-rw-r--r--compiler/rustc_parse/src/parser/path.rs2
-rw-r--r--compiler/rustc_parse/src/parser/ty.rs2
9 files changed, 32 insertions, 27 deletions
diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs
index cec657f7b67..02dab95233a 100644
--- a/compiler/rustc_parse/src/parser/attr.rs
+++ b/compiler/rustc_parse/src/parser/attr.rs
@@ -204,8 +204,11 @@ impl<'a> Parser<'a> {
                             attr_sp,
                             fluent::parse_inner_attr_not_permitted_after_outer_doc_comment,
                         )
-                        .span_label_mv(attr_sp, fluent::parse_label_attr)
-                        .span_label_mv(prev_doc_comment_span, fluent::parse_label_prev_doc_comment)
+                        .with_span_label(attr_sp, fluent::parse_label_attr)
+                        .with_span_label(
+                            prev_doc_comment_span,
+                            fluent::parse_label_prev_doc_comment,
+                        )
                 }
                 Some(InnerAttrForbiddenReason::AfterOuterAttribute { prev_outer_attr_sp }) => self
                     .dcx()
@@ -213,8 +216,8 @@ impl<'a> Parser<'a> {
                         attr_sp,
                         fluent::parse_inner_attr_not_permitted_after_outer_attr,
                     )
-                    .span_label_mv(attr_sp, fluent::parse_label_attr)
-                    .span_label_mv(prev_outer_attr_sp, fluent::parse_label_prev_attr),
+                    .with_span_label(attr_sp, fluent::parse_label_attr)
+                    .with_span_label(prev_outer_attr_sp, fluent::parse_label_prev_attr),
                 Some(InnerAttrForbiddenReason::InCodeBlock) | None => {
                     self.dcx().struct_span_err(attr_sp, fluent::parse_inner_attr_not_permitted)
                 }
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs
index a9cf26d991c..720a610fdf5 100644
--- a/compiler/rustc_parse/src/parser/diagnostics.rs
+++ b/compiler/rustc_parse/src/parser/diagnostics.rs
@@ -2847,8 +2847,8 @@ impl<'a> Parser<'a> {
         let span = label.ident.span.to(self.prev_token.span);
         self.dcx()
             .struct_span_err(span, "block label not supported here")
-            .span_label_mv(span, "not supported here")
-            .tool_only_span_suggestion_mv(
+            .with_span_label(span, "not supported here")
+            .with_tool_only_span_suggestion(
                 label.ident.span.until(self.token.span),
                 "remove this block label",
                 "",
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index db777266b59..8ca02452342 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -1753,7 +1753,7 @@ impl<'a> Parser<'a> {
         err: impl FnOnce(&Self) -> DiagnosticBuilder<'a>,
     ) -> L {
         if let Some(diag) = self.dcx().steal_diagnostic(lifetime.span, StashKey::LifetimeIsChar) {
-            diag.span_suggestion_verbose_mv(
+            diag.with_span_suggestion_verbose(
                 lifetime.span.shrink_to_hi(),
                 "add `'` to close the char literal",
                 "'",
@@ -1762,7 +1762,7 @@ impl<'a> Parser<'a> {
             .emit();
         } else {
             err(self)
-                .span_suggestion_verbose_mv(
+                .with_span_suggestion_verbose(
                     lifetime.span.shrink_to_hi(),
                     "add `'` to close the char literal",
                     "'",
@@ -2150,7 +2150,7 @@ impl<'a> Parser<'a> {
         if [sym::i32, sym::u32, sym::isize, sym::usize].contains(&suffix) {
             // #59553: warn instead of reject out of hand to allow the fix to percolate
             // through the ecosystem when people fix their macros
-            self.dcx().emit_warning(errors::InvalidLiteralSuffixOnTupleIndex {
+            self.dcx().emit_warn(errors::InvalidLiteralSuffixOnTupleIndex {
                 span,
                 suffix,
                 exception: Some(()),
diff --git a/compiler/rustc_parse/src/parser/generics.rs b/compiler/rustc_parse/src/parser/generics.rs
index 66aa8cbcda4..48cf04f7790 100644
--- a/compiler/rustc_parse/src/parser/generics.rs
+++ b/compiler/rustc_parse/src/parser/generics.rs
@@ -145,7 +145,7 @@ impl<'a> Parser<'a> {
                 mistyped_const_ident.span,
                 format!("`const` keyword was mistyped as `{}`", mistyped_const_ident.as_str()),
             )
-            .span_suggestion_verbose_mv(
+            .with_span_suggestion_verbose(
                 mistyped_const_ident.span,
                 "use the `const` keyword",
                 kw::Const.as_str(),
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs
index fed3c83a81d..bcff820da79 100644
--- a/compiler/rustc_parse/src/parser/item.rs
+++ b/compiler/rustc_parse/src/parser/item.rs
@@ -10,7 +10,7 @@ use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree};
 use rustc_ast::util::case::Case;
 use rustc_ast::{self as ast};
 use rustc_ast_pretty::pprust;
-use rustc_errors::{struct_span_err, Applicability, PResult, StashKey};
+use rustc_errors::{struct_span_code_err, Applicability, PResult, StashKey};
 use rustc_span::edit_distance::edit_distance;
 use rustc_span::edition::Edition;
 use rustc_span::source_map;
@@ -741,11 +741,11 @@ impl<'a> Parser<'a> {
                 Ok(Some(item)) => items.extend(item),
                 Err(err) => {
                     self.consume_block(Delimiter::Brace, ConsumeClosingDelim::Yes);
-                    err.span_label_mv(
+                    err.with_span_label(
                         open_brace_span,
                         "while parsing this item list starting here",
                     )
-                    .span_label_mv(self.prev_token.span, "the item list ends here")
+                    .with_span_label(self.prev_token.span, "the item list ends here")
                     .emit();
                     break;
                 }
@@ -759,14 +759,14 @@ impl<'a> Parser<'a> {
         if let token::DocComment(..) = self.token.kind {
             if self.look_ahead(1, |tok| tok == &token::CloseDelim(Delimiter::Brace)) {
                 // FIXME: merge with `DocCommentDoesNotDocumentAnything` (E0585)
-                struct_span_err!(
+                struct_span_code_err!(
                     self.dcx(),
                     self.token.span,
                     E0584,
                     "found a documentation comment that doesn't document anything",
                 )
-                .span_label_mv(self.token.span, "this doc comment doesn't document anything")
-                .help_mv(
+                .with_span_label(self.token.span, "this doc comment doesn't document anything")
+                .with_help(
                     "doc comments must come before what they document, if a comment was \
                     intended use `//`",
                 )
@@ -1218,7 +1218,7 @@ impl<'a> Parser<'a> {
 
                 let before_trait = trai.path.span.shrink_to_lo();
                 let const_up_to_impl = const_span.with_hi(impl_span.lo());
-                err.multipart_suggestion_mv(
+                err.with_multipart_suggestion(
                     "you might have meant to write a const trait impl",
                     vec![(const_up_to_impl, "".to_owned()), (before_trait, "const ".to_owned())],
                     Applicability::MaybeIncorrect,
@@ -1457,7 +1457,7 @@ impl<'a> Parser<'a> {
 
                 if this.token == token::Not {
                     if let Err(err) = this.unexpected::<()>() {
-                        err.note_mv(fluent::parse_macro_expands_to_enum_variant).emit();
+                        err.with_note(fluent::parse_macro_expands_to_enum_variant).emit();
                     }
 
                     this.bump();
@@ -1855,7 +1855,7 @@ impl<'a> Parser<'a> {
             if eq_typo || semi_typo {
                 self.bump();
                 // Gracefully handle small typos.
-                err.span_suggestion_short_mv(
+                err.with_span_suggestion_short(
                     self.prev_token.span,
                     "field names and their types are separated with `:`",
                     ":",
@@ -1935,10 +1935,10 @@ impl<'a> Parser<'a> {
                             lo.to(self.prev_token.span),
                             format!("functions are not allowed in {adt_ty} definitions"),
                         )
-                        .help_mv(
+                        .with_help(
                             "unlike in C++, Java, and C#, functions are declared in `impl` blocks",
                         )
-                        .help_mv("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information")
+                        .with_help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information")
                     }
                     Err(err) => {
                         err.cancel();
@@ -1954,7 +1954,9 @@ impl<'a> Parser<'a> {
                             lo.with_hi(ident.span.hi()),
                             format!("structs are not allowed in {adt_ty} definitions"),
                         )
-                        .help_mv("consider creating a new `struct` definition instead of nesting"),
+                        .with_help(
+                            "consider creating a new `struct` definition instead of nesting",
+                        ),
                     Err(err) => {
                         err.cancel();
                         self.restore_snapshot(snapshot);
diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs
index c13adfb0532..ff2fb6271a8 100644
--- a/compiler/rustc_parse/src/parser/mod.rs
+++ b/compiler/rustc_parse/src/parser/mod.rs
@@ -847,7 +847,7 @@ impl<'a> Parser<'a> {
                                     pprust::token_to_string(&self.prev_token)
                                 );
                                 expect_err
-                                    .span_suggestion_verbose_mv(
+                                    .with_span_suggestion_verbose(
                                         self.prev_token.span.shrink_to_hi().until(self.token.span),
                                         msg,
                                         " @ ",
@@ -863,7 +863,7 @@ impl<'a> Parser<'a> {
                                     // Parsed successfully, therefore most probably the code only
                                     // misses a separator.
                                     expect_err
-                                        .span_suggestion_short_mv(
+                                        .with_span_suggestion_short(
                                             sp,
                                             format!("missing `{token_str}`"),
                                             token_str,
diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs
index 00dc307ab60..7918e03750c 100644
--- a/compiler/rustc_parse/src/parser/pat.rs
+++ b/compiler/rustc_parse/src/parser/pat.rs
@@ -464,7 +464,7 @@ impl<'a> Parser<'a> {
                     self_
                         .dcx()
                         .struct_span_err(self_.token.span, msg)
-                        .span_label_mv(self_.token.span, format!("expected {expected}"))
+                        .with_span_label(self_.token.span, format!("expected {expected}"))
                 });
             PatKind::Lit(self.mk_expr(lo, ExprKind::Lit(lit)))
         } else {
diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs
index 5ad17a30980..e7cad74b4dd 100644
--- a/compiler/rustc_parse/src/parser/path.rs
+++ b/compiler/rustc_parse/src/parser/path.rs
@@ -128,7 +128,7 @@ impl<'a> Parser<'a> {
                 self.prev_token.span,
                 "found single colon before projection in qualified path",
             )
-            .span_suggestion_mv(
+            .with_span_suggestion(
                 self.prev_token.span,
                 "use double colon",
                 "::",
diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs
index 61d72857c36..a4fb92c67ac 100644
--- a/compiler/rustc_parse/src/parser/ty.rs
+++ b/compiler/rustc_parse/src/parser/ty.rs
@@ -1116,7 +1116,7 @@ impl<'a> Parser<'a> {
         let before_fn_path = fn_path.span.shrink_to_lo();
         self.dcx()
             .struct_span_err(generic_args_span, "`Fn` traits cannot take lifetime parameters")
-            .multipart_suggestion_mv(
+            .with_multipart_suggestion(
                 "consider using a higher-ranked trait bound instead",
                 vec![(generic_args_span, "".to_owned()), (before_fn_path, snippet)],
                 Applicability::MaybeIncorrect,