Skip to content

Commit d824edf

Browse files
committed
Do not ICE when synthesizing spans falling inside unicode chars
1 parent 60960a2 commit d824edf

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/libsyntax/source_map.rs

+6
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,14 @@ impl SourceMap {
554554
}
555555

556556
if let Some(ref src) = local_begin.sf.src {
557+
if !src.is_char_boundary(start_index) || !src.is_char_boundary(end_index) {
558+
return Err(SpanSnippetError::IllFormedSpan(sp));
559+
}
557560
return Ok(extract_source(src, start_index, end_index));
558561
} else if let Some(src) = local_begin.sf.external_src.borrow().get_source() {
562+
if !src.is_char_boundary(start_index) || !src.is_char_boundary(end_index) {
563+
return Err(SpanSnippetError::IllFormedSpan(sp));
564+
}
559565
return Ok(extract_source(src, start_index, end_index));
560566
} else {
561567
return Err(SpanSnippetError::SourceNotAvailable {
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
struct X {}
2+
fn f() {
3+
vec![X]; //…
4+
//~^ ERROR expected value, found struct `X`
5+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0423]: expected value, found struct `X`
2+
--> $DIR/issue-61226.rs:3:10
3+
|
4+
LL | vec![X]; //…
5+
| ^
6+
| |
7+
| did you mean `X { /* fields */ }`?
8+
| help: a function with a similar name exists: `f`
9+
10+
error[E0601]: `main` function not found in crate `issue_61226`
11+
|
12+
= note: consider adding a `main` function to `$DIR/issue-61226.rs`
13+
14+
error: aborting due to 2 previous errors
15+
16+
Some errors have detailed explanations: E0423, E0601.
17+
For more information about an error, try `rustc --explain E0423`.

0 commit comments

Comments
 (0)