]> git.lizzy.rs Git - rust.git/commitdiff
extract error_unexpected_after_dot and de-fatalize
authorMazdak Farrokhzad <twingoow@gmail.com>
Fri, 6 Dec 2019 23:59:56 +0000 (00:59 +0100)
committerMazdak Farrokhzad <twingoow@gmail.com>
Mon, 23 Dec 2019 12:45:13 +0000 (13:45 +0100)
src/librustc_parse/parser/expr.rs
src/test/ui/parser/attr-stmt-expr-attr-bad-2.rs [deleted file]
src/test/ui/parser/attr-stmt-expr-attr-bad-2.stderr [deleted file]
src/test/ui/parser/attr-stmt-expr-attr-bad-3.rs [deleted file]
src/test/ui/parser/attr-stmt-expr-attr-bad-3.stderr [deleted file]
src/test/ui/parser/attr-stmt-expr-attr-bad.rs
src/test/ui/parser/attr-stmt-expr-attr-bad.stderr

index 64154aa90740a4d07a783b2df46dbda3d8a85a6a..585ddad5a9e7bcd4118a50c630a0b6124910247f 100644 (file)
@@ -715,11 +715,7 @@ fn parse_dot_or_call_expr_with_(&mut self, e0: P<Expr>, lo: Span) -> PResult<'a,
                             err?
                         }
                     }
-                    _ => {
-                        // FIXME Could factor this out into non_fatal_unexpected or something.
-                        let actual = self.this_token_to_string();
-                        self.span_err(self.token.span, &format!("unexpected token: `{}`", actual));
-                    }
+                    _ => self.error_unexpected_after_dot(),
                 }
                 continue;
             }
@@ -735,6 +731,12 @@ fn parse_dot_or_call_expr_with_(&mut self, e0: P<Expr>, lo: Span) -> PResult<'a,
         return Ok(e);
     }
 
+    fn error_unexpected_after_dot(&self) {
+        // FIXME Could factor this out into non_fatal_unexpected or something.
+        let actual = self.this_token_to_string();
+        self.struct_span_err(self.token.span, &format!("unexpected token: `{}`", actual)).emit();
+    }
+
     fn recover_field_access_by_float_lit(
         &mut self,
         lo: Span,
diff --git a/src/test/ui/parser/attr-stmt-expr-attr-bad-2.rs b/src/test/ui/parser/attr-stmt-expr-attr-bad-2.rs
deleted file mode 100644 (file)
index e5ac59a..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#[cfg(FALSE)] fn e() { let _ = x.#![attr]foo(); }
-//~^ ERROR unexpected token: `#`
diff --git a/src/test/ui/parser/attr-stmt-expr-attr-bad-2.stderr b/src/test/ui/parser/attr-stmt-expr-attr-bad-2.stderr
deleted file mode 100644 (file)
index ca10432..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-error: unexpected token: `#`
-  --> $DIR/attr-stmt-expr-attr-bad-2.rs:1:34
-   |
-LL | #[cfg(FALSE)] fn e() { let _ = x.#![attr]foo(); }
-   |                                  ^
-
-error: aborting due to previous error
-
diff --git a/src/test/ui/parser/attr-stmt-expr-attr-bad-3.rs b/src/test/ui/parser/attr-stmt-expr-attr-bad-3.rs
deleted file mode 100644 (file)
index 7dc71af..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#[cfg(FALSE)] fn e() { let _ = x.#[attr]foo(); }
-//~^ ERROR unexpected token: `#`
diff --git a/src/test/ui/parser/attr-stmt-expr-attr-bad-3.stderr b/src/test/ui/parser/attr-stmt-expr-attr-bad-3.stderr
deleted file mode 100644 (file)
index ab9366d..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-error: unexpected token: `#`
-  --> $DIR/attr-stmt-expr-attr-bad-3.rs:1:34
-   |
-LL | #[cfg(FALSE)] fn e() { let _ = x.#[attr]foo(); }
-   |                                  ^
-
-error: aborting due to previous error
-
index ef10010ed0e617c7bd14d4b5aff7baca6e193455..6e1d72cd2f6e2033473ed6308eb240efbe5982a1 100644 (file)
@@ -101,6 +101,13 @@ fn main() {}
 //~^ ERROR `X..=` range patterns are not supported
 //~| ERROR expected one of `=>`, `if`, or `|`, found `#`
 
+#[cfg(FALSE)] fn e() { let _ = x.#![attr]foo(); }
+//~^ ERROR unexpected token: `#`
+//~| ERROR expected one of `.`
+#[cfg(FALSE)] fn e() { let _ = x.#[attr]foo(); }
+//~^ ERROR unexpected token: `#`
+//~| ERROR expected one of `.`
+
 // make sure we don't catch this bug again...
 #[cfg(FALSE)] fn e() { { fn foo() { #[attr]; } } }
 //~^ ERROR expected statement after outer attribute
index 30aa820141cf9f2d2d205bb35baa4646fb51f393..992b491917ee25849732e1d18174c81bc24a3d67 100644 (file)
@@ -380,11 +380,35 @@ error: expected one of `=>`, `if`, or `|`, found `#`
 LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] FOO => () } }
    |                                      ^ expected one of `=>`, `if`, or `|`
 
+error: unexpected token: `#`
+  --> $DIR/attr-stmt-expr-attr-bad.rs:104:34
+   |
+LL | #[cfg(FALSE)] fn e() { let _ = x.#![attr]foo(); }
+   |                                  ^
+
+error: expected one of `.`, `;`, `?`, or an operator, found `#`
+  --> $DIR/attr-stmt-expr-attr-bad.rs:104:34
+   |
+LL | #[cfg(FALSE)] fn e() { let _ = x.#![attr]foo(); }
+   |                                  ^ expected one of `.`, `;`, `?`, or an operator
+
+error: unexpected token: `#`
+  --> $DIR/attr-stmt-expr-attr-bad.rs:106:34
+   |
+LL | #[cfg(FALSE)] fn e() { let _ = x.#[attr]foo(); }
+   |                                  ^
+
+error: expected one of `.`, `;`, `?`, or an operator, found `#`
+  --> $DIR/attr-stmt-expr-attr-bad.rs:106:34
+   |
+LL | #[cfg(FALSE)] fn e() { let _ = x.#[attr]foo(); }
+   |                                  ^ expected one of `.`, `;`, `?`, or an operator
+
 error: expected statement after outer attribute
-  --> $DIR/attr-stmt-expr-attr-bad.rs:105:44
+  --> $DIR/attr-stmt-expr-attr-bad.rs:110:44
    |
 LL | #[cfg(FALSE)] fn e() { { fn foo() { #[attr]; } } }
    |                                            ^
 
-error: aborting due to 52 previous errors
+error: aborting due to 56 previous errors