]> git.lizzy.rs Git - rust.git/commitdiff
Avoid ICE when suggestion span is at Eof
authorEsteban Küber <esteban@kuber.com.ar>
Thu, 25 Jul 2019 22:59:38 +0000 (15:59 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Thu, 25 Jul 2019 23:06:24 +0000 (16:06 -0700)
src/librustc_errors/lib.rs
src/test/ui/parser/issue-62973.rs [new file with mode: 0644]
src/test/ui/parser/issue-62973.stderr [new file with mode: 0644]

index 3269b85d0dd13243c39a69b3e314e26e89fe9d5f..67fae1f6769237d7538144879ae47d2b2090971d 100644 (file)
@@ -229,7 +229,8 @@ fn push_trailing(buf: &mut String,
                         }
                     }
                     if let Some(cur_line) = fm.get_line(cur_lo.line - 1) {
-                        buf.push_str(&cur_line[..cur_lo.col.to_usize()]);
+                        let end = std::cmp::min(cur_line.len(), cur_lo.col.to_usize());
+                        buf.push_str(&cur_line[..end]);
                     }
                 }
                 buf.push_str(&part.snippet);
diff --git a/src/test/ui/parser/issue-62973.rs b/src/test/ui/parser/issue-62973.rs
new file mode 100644 (file)
index 0000000..c04608e
--- /dev/null
@@ -0,0 +1,8 @@
+// ignore-tidy-end-whitespace
+// error-pattern: aborting due to 6 previous errors
+
+fn main() {}
+
+fn p() { match s { v, E { [) {) }
+
+
diff --git a/src/test/ui/parser/issue-62973.stderr b/src/test/ui/parser/issue-62973.stderr
new file mode 100644 (file)
index 0000000..141076b
--- /dev/null
@@ -0,0 +1,61 @@
+error: this file contains an un-closed delimiter
+  --> $DIR/issue-62973.rs:8:2
+   |
+LL | fn p() { match s { v, E { [) {) }
+   |        -         - un-closed delimiter
+   |        |
+   |        un-closed delimiter
+LL | 
+LL | 
+   |  ^
+
+error: expected one of `,` or `}`, found `{`
+  --> $DIR/issue-62973.rs:6:25
+   |
+LL | fn p() { match s { v, E { [) {) }
+   |                -        ^ expected one of `,` or `}` here
+   |                |
+   |                while parsing this struct
+
+error: struct literals are not allowed here
+  --> $DIR/issue-62973.rs:6:16
+   |
+LL |   fn p() { match s { v, E { [) {) }
+   |  ________________^
+LL | |
+LL | |
+   | |_^
+help: surround the struct literal with parentheses
+   |
+LL | fn p() { match (s { v, E { [) {) }
+LL | 
+LL | )
+   |
+
+error: expected one of `.`, `?`, `{`, or an operator, found `}`
+  --> $DIR/issue-62973.rs:8:1
+   |
+LL | fn p() { match s { v, E { [) {) }
+   |          ----- while parsing this match expression
+LL | 
+LL | 
+   | ^ expected one of `.`, `?`, `{`, or an operator here
+
+error: incorrect close delimiter: `)`
+  --> $DIR/issue-62973.rs:6:28
+   |
+LL | fn p() { match s { v, E { [) {) }
+   |                           -^ incorrect close delimiter
+   |                           |
+   |                           un-closed delimiter
+
+error: incorrect close delimiter: `)`
+  --> $DIR/issue-62973.rs:6:31
+   |
+LL | fn p() { match s { v, E { [) {) }
+   |                              -^ incorrect close delimiter
+   |                              |
+   |                              un-closed delimiter
+
+error: aborting due to 6 previous errors
+