about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-08-12 23:31:13 -0700
committerEsteban Küber <esteban@kuber.com.ar>2019-08-12 23:31:13 -0700
commitd824edfc2c063cff6e6536a1fcb56be6d89fa0cd (patch)
treefd71783c3bbbc6e7cfa30aef1887c7c00893c87d /src
parent60960a260f7b5c695fd0717311d72ce62dd4eb43 (diff)
downloadrust-d824edfc2c063cff6e6536a1fcb56be6d89fa0cd.tar.gz
rust-d824edfc2c063cff6e6536a1fcb56be6d89fa0cd.zip
Do not ICE when synthesizing spans falling inside unicode chars
Diffstat (limited to 'src')
-rw-r--r--src/libsyntax/source_map.rs6
-rw-r--r--src/test/ui/suggestions/issue-61226.rs5
-rw-r--r--src/test/ui/suggestions/issue-61226.stderr17
3 files changed, 28 insertions, 0 deletions
diff --git a/src/libsyntax/source_map.rs b/src/libsyntax/source_map.rs
index 4e29c77c89e..3c58cfbbb2b 100644
--- a/src/libsyntax/source_map.rs
+++ b/src/libsyntax/source_map.rs
@@ -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 {
diff --git a/src/test/ui/suggestions/issue-61226.rs b/src/test/ui/suggestions/issue-61226.rs
new file mode 100644
index 00000000000..1eed55e5f9f
--- /dev/null
+++ b/src/test/ui/suggestions/issue-61226.rs
@@ -0,0 +1,5 @@
+struct X {}
+fn f() {
+    vec![X]; //…
+    //~^ ERROR expected value, found struct `X`
+}
diff --git a/src/test/ui/suggestions/issue-61226.stderr b/src/test/ui/suggestions/issue-61226.stderr
new file mode 100644
index 00000000000..ac27fb1f758
--- /dev/null
+++ b/src/test/ui/suggestions/issue-61226.stderr
@@ -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`.