Skip to content

Commit

Permalink
Do not ICE when synthesizing spans falling inside unicode chars
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Aug 13, 2019
1 parent 60960a2 commit d824edf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/libsyntax/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,14 @@ impl SourceMap {
}

if let Some(ref src) = local_begin.sf.src {
if !src.is_char_boundary(start_index) || !src.is_char_boundary(end_index) {
return Err(SpanSnippetError::IllFormedSpan(sp));
}
return Ok(extract_source(src, start_index, end_index));
} else if let Some(src) = local_begin.sf.external_src.borrow().get_source() {
if !src.is_char_boundary(start_index) || !src.is_char_boundary(end_index) {
return Err(SpanSnippetError::IllFormedSpan(sp));
}
return Ok(extract_source(src, start_index, end_index));
} else {
return Err(SpanSnippetError::SourceNotAvailable {
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/suggestions/issue-61226.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
struct X {}
fn f() {
vec![X]; //…
//~^ ERROR expected value, found struct `X`
}
17 changes: 17 additions & 0 deletions src/test/ui/suggestions/issue-61226.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0423]: expected value, found struct `X`
--> $DIR/issue-61226.rs:3:10
|
LL | vec![X]; //…
| ^
| |
| did you mean `X { /* fields */ }`?
| help: a function with a similar name exists: `f`

error[E0601]: `main` function not found in crate `issue_61226`
|
= note: consider adding a `main` function to `$DIR/issue-61226.rs`

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0423, E0601.
For more information about an error, try `rustc --explain E0423`.

0 comments on commit d824edf

Please sign in to comment.