From f3bdd5ab32e112483da4c81d64ec14a116bf06cf Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 4 Feb 2020 18:20:50 +0000 Subject: Workaround panic in a serde_dhall example Unsure what's causing it, most probably mixing of spans from different inputs --- dhall/src/syntax/ast/span.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'dhall/src/syntax/ast') 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(); -- cgit v1.2.3