about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-03-22 06:09:24 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2020-03-27 07:39:15 +0100
commit2972bb37b8dc6e64ec31cf9b79245974e30f417b (patch)
tree87068e3bccc1ef5b8ce1b572b8f68cdd90fb1bae /src/test
parentf91de44d073e40d6d4682ad41d61cadcc0fcedeb (diff)
downloadrust-2972bb37b8dc6e64ec31cf9b79245974e30f417b.tar.gz
rust-2972bb37b8dc6e64ec31cf9b79245974e30f417b.zip
parse: improve recovery for assoc eq constraints.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/parser/recover-assoc-const-constraint.rs7
-rw-r--r--src/test/ui/parser/recover-assoc-const-constraint.stderr20
-rw-r--r--src/test/ui/parser/recover-assoc-eq-missing-term.rs6
-rw-r--r--src/test/ui/parser/recover-assoc-eq-missing-term.stderr17
-rw-r--r--src/test/ui/parser/recover-assoc-lifetime-constraint.rs6
-rw-r--r--src/test/ui/parser/recover-assoc-lifetime-constraint.stderr12
6 files changed, 68 insertions, 0 deletions
diff --git a/src/test/ui/parser/recover-assoc-const-constraint.rs b/src/test/ui/parser/recover-assoc-const-constraint.rs
new file mode 100644
index 00000000000..06be3cdcc1a
--- /dev/null
+++ b/src/test/ui/parser/recover-assoc-const-constraint.rs
@@ -0,0 +1,7 @@
+#[cfg(FALSE)]
+fn syntax() {
+    bar::<Item = 42>(); //~ ERROR cannot constrain an associated constant to a value
+    bar::<Item = { 42 }>(); //~ ERROR cannot constrain an associated constant to a value
+}
+
+fn main() {}
diff --git a/src/test/ui/parser/recover-assoc-const-constraint.stderr b/src/test/ui/parser/recover-assoc-const-constraint.stderr
new file mode 100644
index 00000000000..bf617207936
--- /dev/null
+++ b/src/test/ui/parser/recover-assoc-const-constraint.stderr
@@ -0,0 +1,20 @@
+error: cannot constrain an associated constant to a value
+  --> $DIR/recover-assoc-const-constraint.rs:3:11
+   |
+LL |     bar::<Item = 42>();
+   |           ----^^^--
+   |           |      |
+   |           |      the value is given in this expression
+   |           the value constrains this associated constant
+
+error: cannot constrain an associated constant to a value
+  --> $DIR/recover-assoc-const-constraint.rs:4:11
+   |
+LL |     bar::<Item = { 42 }>();
+   |           ----^^^------
+   |           |      |
+   |           |      the value is given in this expression
+   |           the value constrains this associated constant
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/parser/recover-assoc-eq-missing-term.rs b/src/test/ui/parser/recover-assoc-eq-missing-term.rs
new file mode 100644
index 00000000000..d800df8236b
--- /dev/null
+++ b/src/test/ui/parser/recover-assoc-eq-missing-term.rs
@@ -0,0 +1,6 @@
+#[cfg(FALSE)]
+fn syntax() {
+    bar::<Item = >(); //~ ERROR missing type to the right of `=`
+}
+
+fn main() {}
diff --git a/src/test/ui/parser/recover-assoc-eq-missing-term.stderr b/src/test/ui/parser/recover-assoc-eq-missing-term.stderr
new file mode 100644
index 00000000000..5eb5d6879e9
--- /dev/null
+++ b/src/test/ui/parser/recover-assoc-eq-missing-term.stderr
@@ -0,0 +1,17 @@
+error: missing type to the right of `=`
+  --> $DIR/recover-assoc-eq-missing-term.rs:3:11
+   |
+LL |     bar::<Item = >();
+   |           ^^^^^^
+   |
+help: to constrain the associated type, add a type after `=`
+   |
+LL |     bar::<Item = TheType >();
+   |           ^^^^^^^^^^^^^^
+help: remove the `=` if `Item` is a type
+   |
+LL |     bar::<Item  >();
+   |               --
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/parser/recover-assoc-lifetime-constraint.rs b/src/test/ui/parser/recover-assoc-lifetime-constraint.rs
new file mode 100644
index 00000000000..558fcdfe177
--- /dev/null
+++ b/src/test/ui/parser/recover-assoc-lifetime-constraint.rs
@@ -0,0 +1,6 @@
+#[cfg(FALSE)]
+fn syntax() {
+    bar::<Item = 'a>(); //~ ERROR associated lifetimes are not supported
+}
+
+fn main() {}
diff --git a/src/test/ui/parser/recover-assoc-lifetime-constraint.stderr b/src/test/ui/parser/recover-assoc-lifetime-constraint.stderr
new file mode 100644
index 00000000000..79437533d7c
--- /dev/null
+++ b/src/test/ui/parser/recover-assoc-lifetime-constraint.stderr
@@ -0,0 +1,12 @@
+error: associated lifetimes are not supported
+  --> $DIR/recover-assoc-lifetime-constraint.rs:3:11
+   |
+LL |     bar::<Item = 'a>();
+   |           ^^^^^^^--
+   |                  |
+   |                  the lifetime is given here
+   |
+   = help: if you meant to specify a trait object, write `dyn Trait + 'lifetime`
+
+error: aborting due to previous error
+