Skip to content

Commit eeb1bd1

Browse files
committed
Avoid ICE when suggestion span is at Eof
1 parent 03f19f7 commit eeb1bd1

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

src/librustc_errors/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ impl CodeSuggestion {
229229
}
230230
}
231231
if let Some(cur_line) = fm.get_line(cur_lo.line - 1) {
232-
buf.push_str(&cur_line[..cur_lo.col.to_usize()]);
232+
let end = std::cmp::min(cur_line.len(), cur_lo.col.to_usize());
233+
buf.push_str(&cur_line[..end]);
233234
}
234235
}
235236
buf.push_str(&part.snippet);

src/test/ui/parser/issue-62973.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// ignore-tidy-end-whitespace
2+
// error-pattern: aborting due to 6 previous errors
3+
4+
fn main() {}
5+
6+
fn p() { match s { v, E { [) {) }
7+
8+

src/test/ui/parser/issue-62973.stderr

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
error: this file contains an un-closed delimiter
2+
--> $DIR/issue-62973.rs:8:2
3+
|
4+
LL | fn p() { match s { v, E { [) {) }
5+
| - - un-closed delimiter
6+
| |
7+
| un-closed delimiter
8+
LL |
9+
LL |
10+
| ^
11+
12+
error: expected one of `,` or `}`, found `{`
13+
--> $DIR/issue-62973.rs:6:25
14+
|
15+
LL | fn p() { match s { v, E { [) {) }
16+
| - ^ expected one of `,` or `}` here
17+
| |
18+
| while parsing this struct
19+
20+
error: struct literals are not allowed here
21+
--> $DIR/issue-62973.rs:6:16
22+
|
23+
LL | fn p() { match s { v, E { [) {) }
24+
| ________________^
25+
LL | |
26+
LL | |
27+
| |_^
28+
help: surround the struct literal with parentheses
29+
|
30+
LL | fn p() { match (s { v, E { [) {) }
31+
LL |
32+
LL | )
33+
|
34+
35+
error: expected one of `.`, `?`, `{`, or an operator, found `}`
36+
--> $DIR/issue-62973.rs:8:1
37+
|
38+
LL | fn p() { match s { v, E { [) {) }
39+
| ----- while parsing this match expression
40+
LL |
41+
LL |
42+
| ^ expected one of `.`, `?`, `{`, or an operator here
43+
44+
error: incorrect close delimiter: `)`
45+
--> $DIR/issue-62973.rs:6:28
46+
|
47+
LL | fn p() { match s { v, E { [) {) }
48+
| -^ incorrect close delimiter
49+
| |
50+
| un-closed delimiter
51+
52+
error: incorrect close delimiter: `)`
53+
--> $DIR/issue-62973.rs:6:31
54+
|
55+
LL | fn p() { match s { v, E { [) {) }
56+
| -^ incorrect close delimiter
57+
| |
58+
| un-closed delimiter
59+
60+
error: aborting due to 6 previous errors
61+

0 commit comments

Comments
 (0)