about summary refs log tree commit diff
path: root/src/test/ui/parser
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2018-09-04 08:09:49 -0700
committerEsteban Küber <esteban@kuber.com.ar>2018-09-05 03:43:24 -0700
commit008aa5a24e152691d852bd9f0a2990b6e4377397 (patch)
tree13847227aed9aaca1f822f60180704fc72576e3a /src/test/ui/parser
parent5238b523c3959e33add469af77b2ffa5a60b4cf6 (diff)
downloadrust-008aa5a24e152691d852bd9f0a2990b6e4377397.tar.gz
rust-008aa5a24e152691d852bd9f0a2990b6e4377397.zip
Provide more context for unenclosed delimiters
 * When encountering EOF, point at the last opening brace that does not
   have the same indentation level as its close delimiter.
 * When encountering the wrong type of close delimiter, point at the
   likely correct open delimiter to give a better idea of what went
   wrong.
Diffstat (limited to 'src/test/ui/parser')
-rw-r--r--src/test/ui/parser/unclosed-braces.rs32
-rw-r--r--src/test/ui/parser/unclosed-braces.stderr17
2 files changed, 49 insertions, 0 deletions
diff --git a/src/test/ui/parser/unclosed-braces.rs b/src/test/ui/parser/unclosed-braces.rs
new file mode 100644
index 00000000000..64089447584
--- /dev/null
+++ b/src/test/ui/parser/unclosed-braces.rs
@@ -0,0 +1,32 @@
+// Copyright 2018 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.
+
+struct S {
+    x: [usize; 3],
+}
+
+fn foo() {
+    {
+        {
+            println!("hi");
+        }
+    }
+}
+
+fn main() {
+//~^ NOTE un-closed delimiter
+    {
+        {
+        //~^ NOTE this might be the culprit...
+            foo();
+    }
+    //~^ NOTE ...as it matches this but it has different indentation
+}
+//~ ERROR this file contains an un-closed delimiter
diff --git a/src/test/ui/parser/unclosed-braces.stderr b/src/test/ui/parser/unclosed-braces.stderr
new file mode 100644
index 00000000000..5d5ff24faa6
--- /dev/null
+++ b/src/test/ui/parser/unclosed-braces.stderr
@@ -0,0 +1,17 @@
+error: this file contains an un-closed delimiter
+  --> $DIR/unclosed-braces.rs:32:53
+   |
+LL | fn main() {
+   |           - un-closed delimiter
+...
+LL |         {
+   |         - this might be the culprit...
+...
+LL |     }
+   |     - ...as it matches this but it has different indentation
+...
+LL | //~ ERROR this file contains an un-closed delimiter
+   |                                                     ^
+
+error: aborting due to previous error
+