summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dhall/src/syntax/ast/span.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/dhall/src/syntax/ast/span.rs b/dhall/src/syntax/ast/span.rs
index ffdd82c..fba6a2d 100644
--- a/dhall/src/syntax/ast/span.rs
+++ b/dhall/src/syntax/ast/span.rs
@@ -100,8 +100,10 @@ fn char_idx_from_byte_idx(input: &str, idx: usize) -> usize {
.char_indices()
.enumerate()
.find(|(_, (i, _))| *i == idx)
- .unwrap()
- .0;
+ .map(|(i, (_, _))| i)
+ // We should be able to unwrap() here, but somehow it panics on an example from
+ // serde_dhall/lib.rs...
+ .unwrap_or(0);
// Unix-style newlines are counted as two chars (see
// https://github.com/rust-lang/annotate-snippets-rs/issues/24).
let nbr_newlines = input[..idx].chars().filter(|c| *c == '\n').count();