summaryrefslogtreecommitdiff
path: root/dhall
diff options
context:
space:
mode:
authorNadrieril2020-02-04 18:20:50 +0000
committerNadrieril2020-02-04 18:25:47 +0000
commitf3bdd5ab32e112483da4c81d64ec14a116bf06cf (patch)
treeb3297ae9f8a46f976274159aa7f4c8ee8662b6f1 /dhall
parentbde4104d061ab87d4af85a083c549ae174797710 (diff)
Workaround panic in a serde_dhall example
Unsure what's causing it, most probably mixing of spans from different inputs
Diffstat (limited to 'dhall')
-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();