about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_parse/src/parser/item.rs44
-rw-r--r--src/test/ui/async-await/await-keyword/2018-edition-error-in-non-macro-position.stderr4
-rw-r--r--src/test/ui/parser/doc-before-struct-rbrace-1.stderr3
-rw-r--r--src/test/ui/parser/fn-field-parse-error-ice.stderr2
-rw-r--r--src/test/ui/parser/issues/issue-101540.stderr2
-rw-r--r--src/test/ui/parser/issues/issue-48636.stderr2
-rw-r--r--src/test/ui/parser/issues/issue-68000-unicode-ident-after-missing-comma.stderr2
-rw-r--r--src/test/ui/parser/macro/issue-37113.stderr2
-rw-r--r--src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr3
-rw-r--r--src/test/ui/parser/missing-closing-angle-bracket-struct-field-ty.stderr3
-rw-r--r--src/test/ui/parser/recover-enum2.stderr2
-rw-r--r--src/test/ui/parser/recover-field-semi.stderr8
-rw-r--r--src/test/ui/parser/recover-struct.stderr2
-rw-r--r--src/test/ui/parser/recovered-struct-variant.stderr4
-rw-r--r--src/test/ui/parser/removed-syntax-enum-newtype.stderr4
-rw-r--r--src/test/ui/parser/removed-syntax-field-let.stderr2
-rw-r--r--src/test/ui/parser/removed-syntax-field-semicolon.stderr2
-rw-r--r--src/test/ui/pattern/issue-66270-pat-struct-parser-recovery.stderr2
-rw-r--r--src/test/ui/proc-macro/derive-bad.stderr5
-rw-r--r--src/test/ui/pub/pub-restricted-error.stderr2
-rw-r--r--src/test/ui/structs/struct-fn-in-definition.stderr9
-rw-r--r--src/test/ui/suggestions/struct-field-type-including-single-colon.stderr4
-rw-r--r--src/test/ui/typeck/issue-69378-ice-on-invalid-type-node-after-recovery.stderr4
23 files changed, 96 insertions, 21 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs
index 34f25bd0716..6c4cfcf6ddf 100644
--- a/compiler/rustc_parse/src/parser/item.rs
+++ b/compiler/rustc_parse/src/parser/item.rs
@@ -1291,12 +1291,10 @@ impl<'a> Parser<'a> {
     /// Parses an enum declaration.
     fn parse_item_enum(&mut self) -> PResult<'a, ItemInfo> {
         if self.token.is_keyword(kw::Struct) {
-            let mut err = self.struct_span_err(
-                self.prev_token.span.to(self.token.span),
-                "`enum` and `struct` are mutually exclusive",
-            );
+            let span = self.prev_token.span.to(self.token.span);
+            let mut err = self.struct_span_err(span, "`enum` and `struct` are mutually exclusive");
             err.span_suggestion(
-                self.prev_token.span.to(self.token.span),
+                span,
                 "replace `enum struct` with",
                 "enum",
                 Applicability::MachineApplicable,
@@ -1320,7 +1318,8 @@ impl<'a> Parser<'a> {
             (vec![], false)
         } else {
             self.parse_delim_comma_seq(Delimiter::Brace, |p| p.parse_enum_variant()).map_err(
-                |e| {
+                |mut e| {
+                    e.span_label(id.span, "while parsing this enum");
                     self.recover_stmt();
                     e
                 },
@@ -1347,7 +1346,8 @@ impl<'a> Parser<'a> {
 
                 let struct_def = if this.check(&token::OpenDelim(Delimiter::Brace)) {
                     // Parse a struct variant.
-                    let (fields, recovered) = this.parse_record_struct_body("struct", false)?;
+                    let (fields, recovered) =
+                        this.parse_record_struct_body("struct", ident.span, false)?;
                     VariantData::Struct(fields, recovered)
                 } else if this.check(&token::OpenDelim(Delimiter::Parenthesis)) {
                     VariantData::Tuple(this.parse_tuple_struct_body()?, DUMMY_NODE_ID)
@@ -1401,8 +1401,11 @@ impl<'a> Parser<'a> {
                 VariantData::Unit(DUMMY_NODE_ID)
             } else {
                 // If we see: `struct Foo<T> where T: Copy { ... }`
-                let (fields, recovered) =
-                    self.parse_record_struct_body("struct", generics.where_clause.has_where_token)?;
+                let (fields, recovered) = self.parse_record_struct_body(
+                    "struct",
+                    class_name.span,
+                    generics.where_clause.has_where_token,
+                )?;
                 VariantData::Struct(fields, recovered)
             }
         // No `where` so: `struct Foo<T>;`
@@ -1410,8 +1413,11 @@ impl<'a> Parser<'a> {
             VariantData::Unit(DUMMY_NODE_ID)
         // Record-style struct definition
         } else if self.token == token::OpenDelim(Delimiter::Brace) {
-            let (fields, recovered) =
-                self.parse_record_struct_body("struct", generics.where_clause.has_where_token)?;
+            let (fields, recovered) = self.parse_record_struct_body(
+                "struct",
+                class_name.span,
+                generics.where_clause.has_where_token,
+            )?;
             VariantData::Struct(fields, recovered)
         // Tuple-style struct definition with optional where-clause.
         } else if self.token == token::OpenDelim(Delimiter::Parenthesis) {
@@ -1440,12 +1446,18 @@ impl<'a> Parser<'a> {
 
         let vdata = if self.token.is_keyword(kw::Where) {
             generics.where_clause = self.parse_where_clause()?;
-            let (fields, recovered) =
-                self.parse_record_struct_body("union", generics.where_clause.has_where_token)?;
+            let (fields, recovered) = self.parse_record_struct_body(
+                "union",
+                class_name.span,
+                generics.where_clause.has_where_token,
+            )?;
             VariantData::Struct(fields, recovered)
         } else if self.token == token::OpenDelim(Delimiter::Brace) {
-            let (fields, recovered) =
-                self.parse_record_struct_body("union", generics.where_clause.has_where_token)?;
+            let (fields, recovered) = self.parse_record_struct_body(
+                "union",
+                class_name.span,
+                generics.where_clause.has_where_token,
+            )?;
             VariantData::Struct(fields, recovered)
         } else {
             let token_str = super::token_descr(&self.token);
@@ -1461,6 +1473,7 @@ impl<'a> Parser<'a> {
     fn parse_record_struct_body(
         &mut self,
         adt_ty: &str,
+        ident_span: Span,
         parsed_where: bool,
     ) -> PResult<'a, (Vec<FieldDef>, /* recovered */ bool)> {
         let mut fields = Vec::new();
@@ -1475,6 +1488,7 @@ impl<'a> Parser<'a> {
                 match field {
                     Ok(field) => fields.push(field),
                     Err(mut err) => {
+                        err.span_label(ident_span, format!("while parsing this {adt_ty}"));
                         err.emit();
                         break;
                     }
diff --git a/src/test/ui/async-await/await-keyword/2018-edition-error-in-non-macro-position.stderr b/src/test/ui/async-await/await-keyword/2018-edition-error-in-non-macro-position.stderr
index ccbaa1f2af0..6bd8f671d73 100644
--- a/src/test/ui/async-await/await-keyword/2018-edition-error-in-non-macro-position.stderr
+++ b/src/test/ui/async-await/await-keyword/2018-edition-error-in-non-macro-position.stderr
@@ -46,7 +46,9 @@ error: expected identifier, found keyword `await`
   --> $DIR/2018-edition-error-in-non-macro-position.rs:13:14
    |
 LL | struct Foo { await: () }
-   |              ^^^^^ expected identifier, found keyword
+   |        ---   ^^^^^ expected identifier, found keyword
+   |        |
+   |        while parsing this struct
    |
 help: escape `await` to use it as an identifier
    |
diff --git a/src/test/ui/parser/doc-before-struct-rbrace-1.stderr b/src/test/ui/parser/doc-before-struct-rbrace-1.stderr
index 19f90677398..92b5133b74d 100644
--- a/src/test/ui/parser/doc-before-struct-rbrace-1.stderr
+++ b/src/test/ui/parser/doc-before-struct-rbrace-1.stderr
@@ -1,6 +1,9 @@
 error[E0585]: found a documentation comment that doesn't document anything
   --> $DIR/doc-before-struct-rbrace-1.rs:3:5
    |
+LL | struct X {
+   |        - while parsing this struct
+LL |     a: u8,
 LL |     /// document
    |     ^^^^^^^^^^^^
    |
diff --git a/src/test/ui/parser/fn-field-parse-error-ice.stderr b/src/test/ui/parser/fn-field-parse-error-ice.stderr
index d582f61cc97..e9583f55b8e 100644
--- a/src/test/ui/parser/fn-field-parse-error-ice.stderr
+++ b/src/test/ui/parser/fn-field-parse-error-ice.stderr
@@ -7,6 +7,8 @@ LL |     inner : dyn fn ()
 error: functions are not allowed in struct definitions
   --> $DIR/fn-field-parse-error-ice.rs:4:17
    |
+LL | struct Baz {
+   |        --- while parsing this struct
 LL |     inner : dyn fn ()
    |                 ^^
    |
diff --git a/src/test/ui/parser/issues/issue-101540.stderr b/src/test/ui/parser/issues/issue-101540.stderr
index 53c7c9590e6..8af88705002 100644
--- a/src/test/ui/parser/issues/issue-101540.stderr
+++ b/src/test/ui/parser/issues/issue-101540.stderr
@@ -1,6 +1,8 @@
 error: structs are not allowed in struct definitions
   --> $DIR/issue-101540.rs:2:5
    |
+LL | struct S1 {
+   |        -- while parsing this struct
 LL |     struct S2 {
    |     ^^^^^^^^^
    |
diff --git a/src/test/ui/parser/issues/issue-48636.stderr b/src/test/ui/parser/issues/issue-48636.stderr
index 462723d1d93..1a6e4cfd2b2 100644
--- a/src/test/ui/parser/issues/issue-48636.stderr
+++ b/src/test/ui/parser/issues/issue-48636.stderr
@@ -1,6 +1,8 @@
 error[E0585]: found a documentation comment that doesn't document anything
   --> $DIR/issue-48636.rs:7:5
    |
+LL | struct S {
+   |        - while parsing this struct
 LL |     x: u8
    |          - help: missing comma here: `,`
 LL |     /// The ID of the parent core
diff --git a/src/test/ui/parser/issues/issue-68000-unicode-ident-after-missing-comma.stderr b/src/test/ui/parser/issues/issue-68000-unicode-ident-after-missing-comma.stderr
index ef365a61643..adabb68593c 100644
--- a/src/test/ui/parser/issues/issue-68000-unicode-ident-after-missing-comma.stderr
+++ b/src/test/ui/parser/issues/issue-68000-unicode-ident-after-missing-comma.stderr
@@ -7,6 +7,8 @@ LL |     pub bar: Vec<i32>ö
 error: expected `:`, found `}`
   --> $DIR/issue-68000-unicode-ident-after-missing-comma.rs:4:1
    |
+LL | pub struct Foo {
+   |            --- while parsing this struct
 LL |     pub bar: Vec<i32>ö
    |                       - expected `:`
 LL |
diff --git a/src/test/ui/parser/macro/issue-37113.stderr b/src/test/ui/parser/macro/issue-37113.stderr
index 0912858ddc4..b1f8674fbdf 100644
--- a/src/test/ui/parser/macro/issue-37113.stderr
+++ b/src/test/ui/parser/macro/issue-37113.stderr
@@ -1,6 +1,8 @@
 error: expected identifier, found `String`
   --> $DIR/issue-37113.rs:4:16
    |
+LL |         enum SomeEnum {
+   |              -------- while parsing this enum
 LL |             $( $t, )*
    |                ^^ expected identifier
 ...
diff --git a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr
index a47d5506ef0..ad1e90e43ec 100644
--- a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr
+++ b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr
@@ -10,6 +10,9 @@ LL | fn main() {}
 error: expected identifier, found keyword `trait`
   --> $DIR/missing-close-brace-in-struct.rs:4:1
    |
+LL | pub(crate) struct Bar<T> {
+   |                   --- while parsing this struct
+...
 LL | trait T {
    | ^^^^^ expected identifier, found keyword
 
diff --git a/src/test/ui/parser/missing-closing-angle-bracket-struct-field-ty.stderr b/src/test/ui/parser/missing-closing-angle-bracket-struct-field-ty.stderr
index 46ca1f06be6..6d8b0c3fccd 100644
--- a/src/test/ui/parser/missing-closing-angle-bracket-struct-field-ty.stderr
+++ b/src/test/ui/parser/missing-closing-angle-bracket-struct-field-ty.stderr
@@ -1,6 +1,9 @@
 error: expected one of `>`, a const expression, lifetime, or type, found `}`
   --> $DIR/missing-closing-angle-bracket-struct-field-ty.rs:9:1
    |
+LL | pub struct Foo {
+   |            --- while parsing this struct
+...
 LL |     c: Arc<Mutex<usize>>,
    |                          - expected one of `>`, a const expression, lifetime, or type
 LL | }
diff --git a/src/test/ui/parser/recover-enum2.stderr b/src/test/ui/parser/recover-enum2.stderr
index ee29f06638f..7634bca921c 100644
--- a/src/test/ui/parser/recover-enum2.stderr
+++ b/src/test/ui/parser/recover-enum2.stderr
@@ -1,6 +1,8 @@
 error: expected type, found `{`
   --> $DIR/recover-enum2.rs:6:18
    |
+LL |         Var3 {
+   |         ---- while parsing this struct
 LL |             abc: {},
    |                  ^ expected type
 
diff --git a/src/test/ui/parser/recover-field-semi.stderr b/src/test/ui/parser/recover-field-semi.stderr
index 657366db9b4..3cf4847488c 100644
--- a/src/test/ui/parser/recover-field-semi.stderr
+++ b/src/test/ui/parser/recover-field-semi.stderr
@@ -1,12 +1,16 @@
 error: struct fields are separated by `,`
   --> $DIR/recover-field-semi.rs:2:13
    |
+LL | struct Foo {
+   |        --- while parsing this struct
 LL |     foo: i32;
    |             ^ help: replace `;` with `,`
 
 error: union fields are separated by `,`
   --> $DIR/recover-field-semi.rs:7:13
    |
+LL | union Bar {
+   |       --- while parsing this union
 LL |     foo: i32;
    |             ^ help: replace `;` with `,`
 
@@ -14,7 +18,9 @@ error: struct fields are separated by `,`
   --> $DIR/recover-field-semi.rs:12:19
    |
 LL |     Qux { foo: i32; }
-   |                   ^ help: replace `;` with `,`
+   |     ---           ^ help: replace `;` with `,`
+   |     |
+   |     while parsing this struct
 
 error: unions cannot have zero fields
   --> $DIR/recover-field-semi.rs:6:1
diff --git a/src/test/ui/parser/recover-struct.stderr b/src/test/ui/parser/recover-struct.stderr
index 1b72184b0c8..9f6fb06caa3 100644
--- a/src/test/ui/parser/recover-struct.stderr
+++ b/src/test/ui/parser/recover-struct.stderr
@@ -1,6 +1,8 @@
 error: expected `:`, found `Bad`
   --> $DIR/recover-struct.rs:4:9
    |
+LL |     struct Test {
+   |            ---- while parsing this struct
 LL |         Very
    |             - expected `:`
 LL |         Bad
diff --git a/src/test/ui/parser/recovered-struct-variant.stderr b/src/test/ui/parser/recovered-struct-variant.stderr
index 51aaf8bb3cf..78c67866fb0 100644
--- a/src/test/ui/parser/recovered-struct-variant.stderr
+++ b/src/test/ui/parser/recovered-struct-variant.stderr
@@ -2,7 +2,9 @@ error: expected `:`, found `,`
   --> $DIR/recovered-struct-variant.rs:2:10
    |
 LL |     A { a, b: usize }
-   |          ^ expected `:`
+   |     -    ^ expected `:`
+   |     |
+   |     while parsing this struct
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/parser/removed-syntax-enum-newtype.stderr b/src/test/ui/parser/removed-syntax-enum-newtype.stderr
index 2daa6249b4c..8f7ca356798 100644
--- a/src/test/ui/parser/removed-syntax-enum-newtype.stderr
+++ b/src/test/ui/parser/removed-syntax-enum-newtype.stderr
@@ -2,7 +2,9 @@ error: expected one of `<`, `where`, or `{`, found `=`
   --> $DIR/removed-syntax-enum-newtype.rs:1:8
    |
 LL | enum e = isize;
-   |        ^ expected one of `<`, `where`, or `{`
+   |      - ^ expected one of `<`, `where`, or `{`
+   |      |
+   |      while parsing this enum
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/parser/removed-syntax-field-let.stderr b/src/test/ui/parser/removed-syntax-field-let.stderr
index 10be2e045b2..ab3d2056581 100644
--- a/src/test/ui/parser/removed-syntax-field-let.stderr
+++ b/src/test/ui/parser/removed-syntax-field-let.stderr
@@ -1,6 +1,8 @@
 error: expected identifier, found keyword `let`
   --> $DIR/removed-syntax-field-let.rs:2:5
    |
+LL | struct S {
+   |        - while parsing this struct
 LL |     let foo: (),
    |     ^^^ expected identifier, found keyword
 
diff --git a/src/test/ui/parser/removed-syntax-field-semicolon.stderr b/src/test/ui/parser/removed-syntax-field-semicolon.stderr
index e4f75f67206..532d4fb2b61 100644
--- a/src/test/ui/parser/removed-syntax-field-semicolon.stderr
+++ b/src/test/ui/parser/removed-syntax-field-semicolon.stderr
@@ -1,6 +1,8 @@
 error: struct fields are separated by `,`
   --> $DIR/removed-syntax-field-semicolon.rs:2:12
    |
+LL | struct S {
+   |        - while parsing this struct
 LL |     bar: ();
    |            ^ help: replace `;` with `,`
 
diff --git a/src/test/ui/pattern/issue-66270-pat-struct-parser-recovery.stderr b/src/test/ui/pattern/issue-66270-pat-struct-parser-recovery.stderr
index fef0f3c0e06..f40642f300c 100644
--- a/src/test/ui/pattern/issue-66270-pat-struct-parser-recovery.stderr
+++ b/src/test/ui/pattern/issue-66270-pat-struct-parser-recovery.stderr
@@ -1,6 +1,8 @@
 error: expected type, found `0`
   --> $DIR/issue-66270-pat-struct-parser-recovery.rs:4:22
    |
+LL | struct Bug {
+   |        --- while parsing this struct
 LL |     incorrect_field: 0,
    |                      ^ expected type
 
diff --git a/src/test/ui/proc-macro/derive-bad.stderr b/src/test/ui/proc-macro/derive-bad.stderr
index ae48141fb31..241f99b28c2 100644
--- a/src/test/ui/proc-macro/derive-bad.stderr
+++ b/src/test/ui/proc-macro/derive-bad.stderr
@@ -2,7 +2,10 @@ error: expected `:`, found `}`
   --> $DIR/derive-bad.rs:6:10
    |
 LL | #[derive(A)]
-   |          ^ expected `:`
+   |          ^
+   |          |
+   |          expected `:`
+   |          while parsing this struct
    |
    = note: this error originates in the derive macro `A` (in Nightly builds, run with -Z macro-backtrace for more info)
 
diff --git a/src/test/ui/pub/pub-restricted-error.stderr b/src/test/ui/pub/pub-restricted-error.stderr
index 95bf498c7f7..b47328f34e6 100644
--- a/src/test/ui/pub/pub-restricted-error.stderr
+++ b/src/test/ui/pub/pub-restricted-error.stderr
@@ -1,6 +1,8 @@
 error: expected identifier, found `(`
   --> $DIR/pub-restricted-error.rs:4:16
    |
+LL | struct Foo {
+   |        --- while parsing this struct
 LL |     pub(crate) () foo: usize,
    |                ^ expected identifier
 
diff --git a/src/test/ui/structs/struct-fn-in-definition.stderr b/src/test/ui/structs/struct-fn-in-definition.stderr
index 1d7cd527295..472365c6ed7 100644
--- a/src/test/ui/structs/struct-fn-in-definition.stderr
+++ b/src/test/ui/structs/struct-fn-in-definition.stderr
@@ -1,6 +1,9 @@
 error: functions are not allowed in struct definitions
   --> $DIR/struct-fn-in-definition.rs:9:5
    |
+LL | struct S {
+   |        - while parsing this struct
+...
 LL |     fn foo() {}
    |     ^^^^^^^^^^^
    |
@@ -10,6 +13,9 @@ LL |     fn foo() {}
 error: functions are not allowed in union definitions
   --> $DIR/struct-fn-in-definition.rs:18:5
    |
+LL | union U {
+   |       - while parsing this union
+...
 LL |     fn foo() {}
    |     ^^^^^^^^^^^
    |
@@ -19,6 +25,9 @@ LL |     fn foo() {}
 error: functions are not allowed in enum definitions
   --> $DIR/struct-fn-in-definition.rs:27:5
    |
+LL | enum E {
+   |      - while parsing this enum
+...
 LL |     fn foo() {}
    |     ^^^^^^^^^^^
    |
diff --git a/src/test/ui/suggestions/struct-field-type-including-single-colon.stderr b/src/test/ui/suggestions/struct-field-type-including-single-colon.stderr
index 189759d64fc..4dd514480da 100644
--- a/src/test/ui/suggestions/struct-field-type-including-single-colon.stderr
+++ b/src/test/ui/suggestions/struct-field-type-including-single-colon.stderr
@@ -12,6 +12,8 @@ LL |     a: foo::A,
 error: expected `,`, or `}`, found `:`
   --> $DIR/struct-field-type-including-single-colon.rs:9:11
    |
+LL | struct Foo {
+   |        --- while parsing this struct
 LL |     a: foo:A,
    |           ^
 
@@ -29,6 +31,8 @@ LL |     b: foo::bar::B,
 error: expected `,`, or `}`, found `:`
   --> $DIR/struct-field-type-including-single-colon.rs:15:16
    |
+LL | struct Bar {
+   |        --- while parsing this struct
 LL |     b: foo::bar:B,
    |                ^
 
diff --git a/src/test/ui/typeck/issue-69378-ice-on-invalid-type-node-after-recovery.stderr b/src/test/ui/typeck/issue-69378-ice-on-invalid-type-node-after-recovery.stderr
index 6bc9c8498c9..fc7c23a2252 100644
--- a/src/test/ui/typeck/issue-69378-ice-on-invalid-type-node-after-recovery.stderr
+++ b/src/test/ui/typeck/issue-69378-ice-on-invalid-type-node-after-recovery.stderr
@@ -2,7 +2,9 @@ error: expected identifier, found `0`
   --> $DIR/issue-69378-ice-on-invalid-type-node-after-recovery.rs:3:14
    |
 LL | struct Foo { 0: u8 }
-   |              ^ expected identifier
+   |        ---   ^ expected identifier
+   |        |
+   |        while parsing this struct
 
 error: aborting due to previous error