about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2018-10-28 16:05:07 -0700
committerEsteban Küber <esteban@kuber.com.ar>2018-10-28 16:05:50 -0700
commit3e22e0c3bc54825f096111bc86ea6e4a6b076ba0 (patch)
tree1ee646f9aee37b8f86ef84f5265d8809e6512bcf
parent3e6f30ec3e6bda159063fcd126dcb14725fef92d (diff)
downloadrust-3e22e0c3bc54825f096111bc86ea6e4a6b076ba0.tar.gz
rust-3e22e0c3bc54825f096111bc86ea6e4a6b076ba0.zip
Use token description in "expected/found" parse messages
-rw-r--r--src/libsyntax/parse/parser.rs48
-rw-r--r--src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.stderr2
-rw-r--r--src/test/ui/if/if-without-block.rs1
-rw-r--r--src/test/ui/if/if-without-block.stderr2
-rw-r--r--src/test/ui/issue-51602.stderr2
-rw-r--r--src/test/ui/issues/issue-39848.stderr2
-rw-r--r--src/test/ui/issues/issue-46186.stderr4
-rw-r--r--src/test/ui/issues/issue-49040.stderr2
-rw-r--r--src/test/ui/label/label_break_value_illegal_uses.stderr2
-rw-r--r--src/test/ui/missing/missing-block-hint.stderr3
-rw-r--r--src/test/ui/missing/missing-semicolon-warning.stderr2
-rw-r--r--src/test/ui/parser/doc-before-identifier.rs2
-rw-r--r--src/test/ui/parser/doc-before-identifier.stderr4
-rw-r--r--src/test/ui/parser/doc-comment-in-if-statement.rs4
-rw-r--r--src/test/ui/parser/doc-comment-in-if-statement.stderr10
-rw-r--r--src/test/ui/parser/import-from-rename.stderr2
-rw-r--r--src/test/ui/parser/import-glob-rename.stderr2
-rw-r--r--src/test/ui/parser/issue-17904-2.rs2
-rw-r--r--src/test/ui/parser/issue-17904-2.stderr4
-rw-r--r--src/test/ui/parser/unsized.rs3
-rw-r--r--src/test/ui/parser/unsized.stderr4
-rw-r--r--src/test/ui/parser/virtual-structs.rs3
-rw-r--r--src/test/ui/parser/virtual-structs.stderr4
23 files changed, 67 insertions, 47 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 589b3e30fcf..003f83a5c6e 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -611,6 +611,7 @@ impl<'a> Parser<'a> {
             t if t.is_special_ident() => "reserved identifier",
             t if t.is_used_keyword() => "keyword",
             t if t.is_unused_keyword() => "reserved keyword",
+            token::DocComment(..) => "doc comment",
             _ => return None,
         })
     }
@@ -644,8 +645,8 @@ impl<'a> Parser<'a> {
                 Ok(())
             } else {
                 let token_str = pprust::token_to_string(t);
-                let this_token_str = self.this_token_to_string();
-                let mut err = self.fatal(&format!("expected `{}`, found `{}`",
+                let this_token_str = self.this_token_descr();
+                let mut err = self.fatal(&format!("expected `{}`, found {}",
                                                   token_str,
                                                   this_token_str));
 
@@ -1444,8 +1445,8 @@ impl<'a> Parser<'a> {
                             Some(body)
                         }
                         _ => {
-                            let token_str = self.this_token_to_string();
-                            let mut err = self.fatal(&format!("expected `;` or `{{`, found `{}`",
+                            let token_str = self.this_token_descr();
+                            let mut err = self.fatal(&format!("expected `;` or `{{`, found {}",
                                                               token_str));
                             err.span_label(self.span, "expected `;` or `{`");
                             return Err(err);
@@ -1453,8 +1454,8 @@ impl<'a> Parser<'a> {
                     }
                 }
                 _ => {
-                    let token_str = self.this_token_to_string();
-                    let mut err = self.fatal(&format!("expected `;` or `{{`, found `{}`",
+                    let token_str = self.this_token_descr();
+                    let mut err = self.fatal(&format!("expected `;` or `{{`, found {}",
                                                       token_str));
                     err.span_label(self.span, "expected `;` or `{`");
                     return Err(err);
@@ -3917,8 +3918,8 @@ impl<'a> Parser<'a> {
                     etc_span = Some(etc_sp);
                     break;
                 }
-                let token_str = self.this_token_to_string();
-                let mut err = self.fatal(&format!("expected `}}`, found `{}`", token_str));
+                let token_str = self.this_token_descr();
+                let mut err = self.fatal(&format!("expected `}}`, found {}", token_str));
 
                 err.span_label(self.span, "expected `}`");
                 let mut comma_sp = None;
@@ -4680,8 +4681,8 @@ impl<'a> Parser<'a> {
                     } else {
                         ""
                     };
-                    let tok_str = self.this_token_to_string();
-                    let mut err = self.fatal(&format!("expected {}`(` or `{{`, found `{}`",
+                    let tok_str = self.this_token_descr();
+                    let mut err = self.fatal(&format!("expected {}`(` or `{{`, found {}",
                                                       ident_str,
                                                       tok_str));
                     err.span_label(self.span, format!("expected {}`(` or `{{`", ident_str));
@@ -4817,8 +4818,8 @@ impl<'a> Parser<'a> {
 
         if !self.eat(&token::OpenDelim(token::Brace)) {
             let sp = self.span;
-            let tok = self.this_token_to_string();
-            let mut e = self.span_fatal(sp, &format!("expected `{{`, found `{}`", tok));
+            let tok = self.this_token_descr();
+            let mut e = self.span_fatal(sp, &format!("expected `{{`, found {}", tok));
             let do_not_suggest_help =
                 self.token.is_keyword(keywords::In) || self.token == token::Colon;
 
@@ -4880,6 +4881,7 @@ impl<'a> Parser<'a> {
                 }
                 _ => ()
             }
+            e.span_label(sp, "expected `{`");
             return Err(e);
         }
 
@@ -4975,7 +4977,7 @@ impl<'a> Parser<'a> {
 
     fn warn_missing_semicolon(&self) {
         self.diagnostic().struct_span_warn(self.span, {
-            &format!("expected `;`, found `{}`", self.this_token_to_string())
+            &format!("expected `;`, found {}", self.this_token_descr())
         }).note({
             "This was erroneously allowed and will become a hard error in a future release"
         }).emit();
@@ -6014,9 +6016,9 @@ impl<'a> Parser<'a> {
             self.expect(&token::Semi)?;
             body
         } else {
-            let token_str = self.this_token_to_string();
+            let token_str = self.this_token_descr();
             let mut err = self.fatal(&format!(
-                "expected `where`, `{{`, `(`, or `;` after struct name, found `{}`",
+                "expected `where`, `{{`, `(`, or `;` after struct name, found {}",
                 token_str
             ));
             err.span_label(self.span, "expected `where`, `{`, `(`, or `;` after struct name");
@@ -6038,9 +6040,9 @@ impl<'a> Parser<'a> {
         } else if self.token == token::OpenDelim(token::Brace) {
             VariantData::Struct(self.parse_record_struct_body()?, ast::DUMMY_NODE_ID)
         } else {
-            let token_str = self.this_token_to_string();
+            let token_str = self.this_token_descr();
             let mut err = self.fatal(&format!(
-                "expected `where` or `{{` after union name, found `{}`", token_str));
+                "expected `where` or `{{` after union name, found {}", token_str));
             err.span_label(self.span, "expected `where` or `{` after union name");
             return Err(err);
         };
@@ -6088,9 +6090,9 @@ impl<'a> Parser<'a> {
             }
             self.eat(&token::CloseDelim(token::Brace));
         } else {
-            let token_str = self.this_token_to_string();
+            let token_str = self.this_token_descr();
             let mut err = self.fatal(&format!(
-                    "expected `where`, or `{{` after struct name, found `{}`", token_str));
+                    "expected `where`, or `{{` after struct name, found {}", token_str));
             err.span_label(self.span, "expected `where`, or `{` after struct name");
             return Err(err);
         }
@@ -6166,8 +6168,8 @@ impl<'a> Parser<'a> {
             }
             _ => {
                 let sp = self.sess.source_map().next_point(self.prev_span);
-                let mut err = self.struct_span_err(sp, &format!("expected `,`, or `}}`, found `{}`",
-                                                                self.this_token_to_string()));
+                let mut err = self.struct_span_err(sp, &format!("expected `,`, or `}}`, found {}",
+                                                                self.this_token_descr()));
                 if self.token.is_ident() {
                     // This is likely another field; emit the diagnostic and keep going
                     err.span_suggestion_with_applicability(
@@ -6303,8 +6305,8 @@ impl<'a> Parser<'a> {
         }
 
         if !self.eat(term) {
-            let token_str = self.this_token_to_string();
-            let mut err = self.fatal(&format!("expected item, found `{}`", token_str));
+            let token_str = self.this_token_descr();
+            let mut err = self.fatal(&format!("expected item, found {}", token_str));
             if token_str == ";" {
                 let msg = "consider removing this semicolon";
                 err.span_suggestion_short_with_applicability(
diff --git a/src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.stderr b/src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.stderr
index db3478116cb..8b6e34c585f 100644
--- a/src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.stderr
+++ b/src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.stderr
@@ -28,7 +28,7 @@ error: expected `{`, found `;`
 LL |     if not  // lack of braces is [sic]
    |     -- this `if` statement has a condition, but no block
 LL |         println!("Then when?");
-   |                               ^
+   |                               ^ expected `{`
 
 error: unexpected `2` after identifier
   --> $DIR/issue-46836-identifier-not-instead-of-negation.rs:36:24
diff --git a/src/test/ui/if/if-without-block.rs b/src/test/ui/if/if-without-block.rs
index ce3de3b302d..db81f00a9e3 100644
--- a/src/test/ui/if/if-without-block.rs
+++ b/src/test/ui/if/if-without-block.rs
@@ -16,3 +16,4 @@ fn main() {
     }
 }
 //~^ ERROR expected `{`, found `}`
+//~| NOTE expected `{`
diff --git a/src/test/ui/if/if-without-block.stderr b/src/test/ui/if/if-without-block.stderr
index bc8e7310ce3..c94dac8871d 100644
--- a/src/test/ui/if/if-without-block.stderr
+++ b/src/test/ui/if/if-without-block.stderr
@@ -5,7 +5,7 @@ LL |     if 5 == {
    |     -- this `if` statement has a condition, but no block
 ...
 LL | }
-   | ^
+   | ^ expected `{`
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/issue-51602.stderr b/src/test/ui/issue-51602.stderr
index ac079b452c5..d50ee64cf52 100644
--- a/src/test/ui/issue-51602.stderr
+++ b/src/test/ui/issue-51602.stderr
@@ -1,4 +1,4 @@
-error: expected `{`, found `in`
+error: expected `{`, found keyword `in`
   --> $DIR/issue-51602.rs:12:10
    |
 LL |     if i in 1..10 {
diff --git a/src/test/ui/issues/issue-39848.stderr b/src/test/ui/issues/issue-39848.stderr
index 9ca39dbaa34..a5d30b8561a 100644
--- a/src/test/ui/issues/issue-39848.stderr
+++ b/src/test/ui/issues/issue-39848.stderr
@@ -7,7 +7,7 @@ LL |         if $tgt.has_$field() {}
    |         this `if` statement has a condition, but no block
 ...
 LL |     get_opt!(bar, foo);
-   |                   ^^^
+   |                   ^^^ expected `{`
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/issues/issue-46186.stderr b/src/test/ui/issues/issue-46186.stderr
index c64d5c68a79..1482b204d64 100644
--- a/src/test/ui/issues/issue-46186.stderr
+++ b/src/test/ui/issues/issue-46186.stderr
@@ -2,9 +2,7 @@ error: expected item, found `;`
   --> $DIR/issue-46186.rs:13:2
    |
 LL | }; //~ ERROR expected item, found `;`
-   |  ^ help: consider removing this semicolon
-   |
-   = help: braced struct declarations are not followed by a semicolon
+   |  ^ expected item
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/issues/issue-49040.stderr b/src/test/ui/issues/issue-49040.stderr
index b6f624dac7d..5fc3528e74b 100644
--- a/src/test/ui/issues/issue-49040.stderr
+++ b/src/test/ui/issues/issue-49040.stderr
@@ -2,7 +2,7 @@ error: expected item, found `;`
   --> $DIR/issue-49040.rs:11:28
    |
 LL | #![allow(unused_variables)]; //~ ERROR expected item, found `;`
-   |                            ^ help: consider removing this semicolon
+   |                            ^ expected item
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/label/label_break_value_illegal_uses.stderr b/src/test/ui/label/label_break_value_illegal_uses.stderr
index 0ab1ad2c242..756648f5658 100644
--- a/src/test/ui/label/label_break_value_illegal_uses.stderr
+++ b/src/test/ui/label/label_break_value_illegal_uses.stderr
@@ -10,6 +10,7 @@ error: expected `{`, found `'b`
 LL |     if true 'b: {} //~ ERROR expected `{`, found `'b`
    |     --      ^^----
    |     |       |
+   |     |       expected `{`
    |     |       help: try placing this code inside a block: `{ 'b: { } }`
    |     this `if` statement has a condition, but no block
 
@@ -19,6 +20,7 @@ error: expected `{`, found `'b`
 LL |     if true {} else 'b: {} //~ ERROR expected `{`, found `'b`
    |                     ^^----
    |                     |
+   |                     expected `{`
    |                     help: try placing this code inside a block: `{ 'b: { } }`
 
 error: expected one of `.`, `?`, `{`, or an operator, found `'b`
diff --git a/src/test/ui/missing/missing-block-hint.stderr b/src/test/ui/missing/missing-block-hint.stderr
index a48eff890b3..dbbfd10b795 100644
--- a/src/test/ui/missing/missing-block-hint.stderr
+++ b/src/test/ui/missing/missing-block-hint.stderr
@@ -2,7 +2,7 @@ error: expected `{`, found `=>`
   --> $DIR/missing-block-hint.rs:13:18
    |
 LL |         if (foo) => {} //~ ERROR expected `{`, found `=>`
-   |         --       ^^
+   |         --       ^^ expected `{`
    |         |
    |         this `if` statement has a condition, but no block
 
@@ -14,6 +14,7 @@ LL |         if (foo)
 LL |             bar; //~ ERROR expected `{`, found `bar`
    |             ^^^-
    |             |
+   |             expected `{`
    |             help: try placing this code inside a block: `{ bar; }`
 
 error: aborting due to 2 previous errors
diff --git a/src/test/ui/missing/missing-semicolon-warning.stderr b/src/test/ui/missing/missing-semicolon-warning.stderr
index 72319a257d8..b4427565a86 100644
--- a/src/test/ui/missing/missing-semicolon-warning.stderr
+++ b/src/test/ui/missing/missing-semicolon-warning.stderr
@@ -1,4 +1,4 @@
-warning: expected `;`, found `let`
+warning: expected `;`, found keyword `let`
   --> $DIR/missing-semicolon-warning.rs:16:12
    |
 LL |         $( let x = $e1 )*; //~ WARN expected `;`
diff --git a/src/test/ui/parser/doc-before-identifier.rs b/src/test/ui/parser/doc-before-identifier.rs
index 2882364081a..a321d0e29b2 100644
--- a/src/test/ui/parser/doc-before-identifier.rs
+++ b/src/test/ui/parser/doc-before-identifier.rs
@@ -12,7 +12,7 @@
 
 fn /// document
 foo() {}
-//~^^ ERROR expected identifier, found `/// document`
+//~^^ ERROR expected identifier, found doc comment `/// document`
 
 fn main() {
     foo();
diff --git a/src/test/ui/parser/doc-before-identifier.stderr b/src/test/ui/parser/doc-before-identifier.stderr
index f93ab634c28..73b169ce8e5 100644
--- a/src/test/ui/parser/doc-before-identifier.stderr
+++ b/src/test/ui/parser/doc-before-identifier.stderr
@@ -1,8 +1,8 @@
-error: expected identifier, found `/// document`
+error: expected identifier, found doc comment `/// document`
   --> $DIR/doc-before-identifier.rs:13:4
    |
 LL | fn /// document
-   |    ^^^^^^^^^^^^ expected identifier
+   |    ^^^^^^^^^^^^ expected identifier, found doc comment
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/parser/doc-comment-in-if-statement.rs b/src/test/ui/parser/doc-comment-in-if-statement.rs
new file mode 100644
index 00000000000..c85fe25a7d0
--- /dev/null
+++ b/src/test/ui/parser/doc-comment-in-if-statement.rs
@@ -0,0 +1,4 @@
+fn main() {
+    if true /*!*/ {}
+    //~^ ERROR expected `{`, found doc comment `/*!*/`
+}
diff --git a/src/test/ui/parser/doc-comment-in-if-statement.stderr b/src/test/ui/parser/doc-comment-in-if-statement.stderr
new file mode 100644
index 00000000000..6bcb77385d7
--- /dev/null
+++ b/src/test/ui/parser/doc-comment-in-if-statement.stderr
@@ -0,0 +1,10 @@
+error: expected `{`, found doc comment `/*!*/`
+  --> $DIR/doc-comment-in-if-statement.rs:2:13
+   |
+LL |     if true /*!*/ {}
+   |     --      ^^^^^ expected `{`
+   |     |
+   |     this `if` statement has a condition, but no block
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/parser/import-from-rename.stderr b/src/test/ui/parser/import-from-rename.stderr
index 6fdc7972a88..f00bfcb45b1 100644
--- a/src/test/ui/parser/import-from-rename.stderr
+++ b/src/test/ui/parser/import-from-rename.stderr
@@ -1,4 +1,4 @@
-error: expected `;`, found `as`
+error: expected `;`, found keyword `as`
   --> $DIR/import-from-rename.rs:15:16
    |
 LL | use foo::{bar} as baz;
diff --git a/src/test/ui/parser/import-glob-rename.stderr b/src/test/ui/parser/import-glob-rename.stderr
index c36a946fd63..0b124a32df3 100644
--- a/src/test/ui/parser/import-glob-rename.stderr
+++ b/src/test/ui/parser/import-glob-rename.stderr
@@ -1,4 +1,4 @@
-error: expected `;`, found `as`
+error: expected `;`, found keyword `as`
   --> $DIR/import-glob-rename.rs:15:12
    |
 LL | use foo::* as baz;
diff --git a/src/test/ui/parser/issue-17904-2.rs b/src/test/ui/parser/issue-17904-2.rs
index 3f41c0edd2e..749cb7fcc0b 100644
--- a/src/test/ui/parser/issue-17904-2.rs
+++ b/src/test/ui/parser/issue-17904-2.rs
@@ -10,6 +10,6 @@
 
 // compile-flags: -Z parse-only -Z continue-parse-after-error
 
-struct Bar<T> { x: T } where T: Copy //~ ERROR expected item, found `where`
+struct Bar<T> { x: T } where T: Copy //~ ERROR expected item, found keyword `where`
 
 fn main() {}
diff --git a/src/test/ui/parser/issue-17904-2.stderr b/src/test/ui/parser/issue-17904-2.stderr
index 65ddadb011d..ff9e1215f10 100644
--- a/src/test/ui/parser/issue-17904-2.stderr
+++ b/src/test/ui/parser/issue-17904-2.stderr
@@ -1,7 +1,7 @@
-error: expected item, found `where`
+error: expected item, found keyword `where`
   --> $DIR/issue-17904-2.rs:13:24
    |
-LL | struct Bar<T> { x: T } where T: Copy //~ ERROR expected item, found `where`
+LL | struct Bar<T> { x: T } where T: Copy //~ ERROR expected item, found keyword `where`
    |                        ^^^^^ expected item
 
 error: aborting due to previous error
diff --git a/src/test/ui/parser/unsized.rs b/src/test/ui/parser/unsized.rs
index 1bcb5208d76..533b947b79a 100644
--- a/src/test/ui/parser/unsized.rs
+++ b/src/test/ui/parser/unsized.rs
@@ -12,7 +12,8 @@
 
 // Test syntax checks for `type` keyword.
 
-struct S1 for type; //~ ERROR expected `where`, `{`, `(`, or `;` after struct name, found `for`
+struct S1 for type;
+//~^ ERROR expected `where`, `{`, `(`, or `;` after struct name, found keyword `for`
 
 pub fn main() {
 }
diff --git a/src/test/ui/parser/unsized.stderr b/src/test/ui/parser/unsized.stderr
index 89de7ee8758..cc35c2035ea 100644
--- a/src/test/ui/parser/unsized.stderr
+++ b/src/test/ui/parser/unsized.stderr
@@ -1,7 +1,7 @@
-error: expected `where`, `{`, `(`, or `;` after struct name, found `for`
+error: expected `where`, `{`, `(`, or `;` after struct name, found keyword `for`
   --> $DIR/unsized.rs:15:11
    |
-LL | struct S1 for type; //~ ERROR expected `where`, `{`, `(`, or `;` after struct name, found `for`
+LL | struct S1 for type;
    |           ^^^ expected `where`, `{`, `(`, or `;` after struct name
 
 error: aborting due to previous error
diff --git a/src/test/ui/parser/virtual-structs.rs b/src/test/ui/parser/virtual-structs.rs
index f34eddc93c5..b7426140d8a 100644
--- a/src/test/ui/parser/virtual-structs.rs
+++ b/src/test/ui/parser/virtual-structs.rs
@@ -12,7 +12,8 @@
 
 // Test diagnostics for the removed struct inheritance feature.
 
-virtual struct SuperStruct { //~ ERROR expected item, found `virtual`
+virtual struct SuperStruct {
+//~^ ERROR expected item, found reserved keyword `virtual`
     f1: isize,
 }
 
diff --git a/src/test/ui/parser/virtual-structs.stderr b/src/test/ui/parser/virtual-structs.stderr
index 6af9922a698..659c7701c00 100644
--- a/src/test/ui/parser/virtual-structs.stderr
+++ b/src/test/ui/parser/virtual-structs.stderr
@@ -1,7 +1,7 @@
-error: expected item, found `virtual`
+error: expected item, found reserved keyword `virtual`
   --> $DIR/virtual-structs.rs:15:1
    |
-LL | virtual struct SuperStruct { //~ ERROR expected item, found `virtual`
+LL | virtual struct SuperStruct {
    | ^^^^^^^ expected item
 
 error: aborting due to previous error