about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorJames Miller <james@aatch.net>2016-08-23 18:23:31 +1200
committerJames Miller <james@aatch.net>2016-08-23 18:23:31 +1200
commit72d629caa50fa482dd4165cb43b9fb02ac24c8d8 (patch)
tree1c140a34db4fa49bd2d6a59150a8cb5faa18e884 /src/test
parent3c5a0fa45b5e2786b6e64e27f48cd129e7aefdbd (diff)
downloadrust-72d629caa50fa482dd4165cb43b9fb02ac24c8d8.tar.gz
rust-72d629caa50fa482dd4165cb43b9fb02ac24c8d8.zip
Improve error message when failing to parse a block
We want to catch this error:

```
if (foo)
    bar;
```

as it's valid syntax in other languages, and say how to fix it.
Unfortunately it didn't care if the suggestion made sense and just
highlighted the unexpected token.

Now it attempts to parse a statement, and if it succeeds, it shows the
help message.

Fixes #35907
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/missing-block-hint.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/test/compile-fail/missing-block-hint.rs b/src/test/compile-fail/missing-block-hint.rs
new file mode 100644
index 00000000000..1f29ff4e05c
--- /dev/null
+++ b/src/test/compile-fail/missing-block-hint.rs
@@ -0,0 +1,20 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+    {
+        if (foo) => {} //~ ERROR expected `{`, found `=>`
+    }
+    {
+        if (foo)
+            bar; //~ ERROR expected `{`, found `bar`
+                 //^ HELP try placing this code inside a block
+    }
+}