about summary refs log tree commit diff
path: root/src/test/ui/parser
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev@gmail.com>2020-12-31 07:53:54 +0900
committerYuki Okushi <huyuumi.dev@gmail.com>2020-12-31 07:53:54 +0900
commit6871d43d4cd1f7df246958af6c552911ef7a8933 (patch)
tree0db3ed7f963c7663b4df8889270c6bc4bfefa6d6 /src/test/ui/parser
parent507bff92fadf1f25a830da5065a5a87113345163 (diff)
Move parser-related tests
Diffstat (limited to 'src/test/ui/parser')
-rw-r--r--src/test/ui/parser/parse-assoc-type-lt.rs9
-rw-r--r--src/test/ui/parser/parse-error-correct.rs10
-rw-r--r--src/test/ui/parser/parse-error-correct.stderr33
-rw-r--r--src/test/ui/parser/parse-panic.rs8
-rw-r--r--src/test/ui/parser/parser-recovery-1.rs13
-rw-r--r--src/test/ui/parser/parser-recovery-1.stderr35
-rw-r--r--src/test/ui/parser/parser-recovery-2.rs12
-rw-r--r--src/test/ui/parser/parser-recovery-2.stderr30
-rw-r--r--src/test/ui/parser/parser-unicode-whitespace.rs12
9 files changed, 162 insertions, 0 deletions
diff --git a/src/test/ui/parser/parse-assoc-type-lt.rs b/src/test/ui/parser/parse-assoc-type-lt.rs
new file mode 100644
index 00000000000..d3fe6079a5d
--- /dev/null
+++ b/src/test/ui/parser/parse-assoc-type-lt.rs
@@ -0,0 +1,9 @@
+// run-pass
+// pretty-expanded FIXME #23616
+
+trait Foo {
+    type T;
+    fn foo() -> Box<<Self as Foo>::T>;
+}
+
+fn main() {}
diff --git a/src/test/ui/parser/parse-error-correct.rs b/src/test/ui/parser/parse-error-correct.rs
new file mode 100644
index 00000000000..13759a23519
--- /dev/null
+++ b/src/test/ui/parser/parse-error-correct.rs
@@ -0,0 +1,10 @@
+// Test that the parser is error correcting missing idents. Despite a parsing
+// error (or two), we still run type checking (and don't get extra errors there).
+
+fn main() {
+    let y = 42;
+    let x = y.;  //~ ERROR unexpected token
+    let x = y.();  //~ ERROR unexpected token
+                   //~^ ERROR expected function, found `{integer}`
+    let x = y.foo; //~ ERROR `{integer}` is a primitive type and therefore doesn't have fields [E061
+}
diff --git a/src/test/ui/parser/parse-error-correct.stderr b/src/test/ui/parser/parse-error-correct.stderr
new file mode 100644
index 00000000000..c54baf00b27
--- /dev/null
+++ b/src/test/ui/parser/parse-error-correct.stderr
@@ -0,0 +1,33 @@
+error: unexpected token: `;`
+  --> $DIR/parse-error-correct.rs:6:15
+   |
+LL |     let x = y.;
+   |               ^
+
+error: unexpected token: `(`
+  --> $DIR/parse-error-correct.rs:7:15
+   |
+LL |     let x = y.();
+   |               ^
+
+error[E0618]: expected function, found `{integer}`
+  --> $DIR/parse-error-correct.rs:7:13
+   |
+LL |     let y = 42;
+   |         - `{integer}` defined here
+LL |     let x = y.;
+LL |     let x = y.();
+   |             ^---
+   |             |
+   |             call expression requires function
+
+error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
+  --> $DIR/parse-error-correct.rs:9:15
+   |
+LL |     let x = y.foo;
+   |               ^^^
+
+error: aborting due to 4 previous errors
+
+Some errors have detailed explanations: E0610, E0618.
+For more information about an error, try `rustc --explain E0610`.
diff --git a/src/test/ui/parser/parse-panic.rs b/src/test/ui/parser/parse-panic.rs
new file mode 100644
index 00000000000..aeb2ba4faa5
--- /dev/null
+++ b/src/test/ui/parser/parse-panic.rs
@@ -0,0 +1,8 @@
+// run-pass
+
+#![allow(dead_code)]
+#![allow(unreachable_code)]
+
+fn dont_call_me() { panic!(); println!("{}", 1); }
+
+pub fn main() { }
diff --git a/src/test/ui/parser/parser-recovery-1.rs b/src/test/ui/parser/parser-recovery-1.rs
new file mode 100644
index 00000000000..7e26b4f2b6a
--- /dev/null
+++ b/src/test/ui/parser/parser-recovery-1.rs
@@ -0,0 +1,13 @@
+// Test that we can recover from missing braces in the parser.
+
+trait Foo {
+    fn bar() {
+        let x = foo();
+        //~^ ERROR cannot find function `foo` in this scope
+}
+
+fn main() {
+    let x = y.;
+    //~^ ERROR unexpected token
+    //~| ERROR cannot find value `y` in this scope
+} //~ ERROR this file contains an unclosed delimiter
diff --git a/src/test/ui/parser/parser-recovery-1.stderr b/src/test/ui/parser/parser-recovery-1.stderr
new file mode 100644
index 00000000000..f56060c3e35
--- /dev/null
+++ b/src/test/ui/parser/parser-recovery-1.stderr
@@ -0,0 +1,35 @@
+error: this file contains an unclosed delimiter
+  --> $DIR/parser-recovery-1.rs:13:54
+   |
+LL | trait Foo {
+   |           - unclosed delimiter
+LL |     fn bar() {
+   |              - this delimiter might not be properly closed...
+...
+LL | }
+   | - ...as it matches this but it has different indentation
+...
+LL | }
+   |                                                      ^
+
+error: unexpected token: `;`
+  --> $DIR/parser-recovery-1.rs:10:15
+   |
+LL |     let x = y.;
+   |               ^
+
+error[E0425]: cannot find function `foo` in this scope
+  --> $DIR/parser-recovery-1.rs:5:17
+   |
+LL |         let x = foo();
+   |                 ^^^ not found in this scope
+
+error[E0425]: cannot find value `y` in this scope
+  --> $DIR/parser-recovery-1.rs:10:13
+   |
+LL |     let x = y.;
+   |             ^ not found in this scope
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/parser/parser-recovery-2.rs b/src/test/ui/parser/parser-recovery-2.rs
new file mode 100644
index 00000000000..48b22afffe7
--- /dev/null
+++ b/src/test/ui/parser/parser-recovery-2.rs
@@ -0,0 +1,12 @@
+// Test that we can recover from mismatched braces in the parser.
+
+trait Foo {
+    fn bar() {
+        let x = foo(); //~ ERROR cannot find function `foo` in this scope
+    ) //~ ERROR mismatched closing delimiter: `)`
+}
+
+fn main() {
+    let x = y.;  //~ ERROR unexpected token
+                 //~^ ERROR cannot find value `y` in this scope
+}
diff --git a/src/test/ui/parser/parser-recovery-2.stderr b/src/test/ui/parser/parser-recovery-2.stderr
new file mode 100644
index 00000000000..cd3da4c71f0
--- /dev/null
+++ b/src/test/ui/parser/parser-recovery-2.stderr
@@ -0,0 +1,30 @@
+error: unexpected token: `;`
+  --> $DIR/parser-recovery-2.rs:10:15
+   |
+LL |     let x = y.;
+   |               ^
+
+error: mismatched closing delimiter: `)`
+  --> $DIR/parser-recovery-2.rs:6:5
+   |
+LL |     fn bar() {
+   |              - unclosed delimiter
+LL |         let x = foo();
+LL |     )
+   |     ^ mismatched closing delimiter
+
+error[E0425]: cannot find function `foo` in this scope
+  --> $DIR/parser-recovery-2.rs:5:17
+   |
+LL |         let x = foo();
+   |                 ^^^ not found in this scope
+
+error[E0425]: cannot find value `y` in this scope
+  --> $DIR/parser-recovery-2.rs:10:13
+   |
+LL |     let x = y.;
+   |             ^ not found in this scope
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/parser/parser-unicode-whitespace.rs b/src/test/ui/parser/parser-unicode-whitespace.rs
new file mode 100644
index 00000000000..2d1fa7dc42e
--- /dev/null
+++ b/src/test/ui/parser/parser-unicode-whitespace.rs
@@ -0,0 +1,12 @@
+// run-pass
+// Beware editing: it has numerous whitespace characters which are important.
+// It contains one ranges from the 'PATTERN_WHITE_SPACE' property outlined in
+// http://unicode.org/Public/UNIDATA/PropList.txt
+//
+// The characters in the first expression of the assertion can be generated
+// from: "4\u{0C}+\n\t\r7\t*\u{20}2\u{85}/\u{200E}3\u{200F}*\u{2028}2\u{2029}"
+pub fn main() {
+assert_eq!(4+
+
+7   * 2…/‎3‏*
2
, 4 + 7 * 2 / 3 * 2);
+}