summaryrefslogtreecommitdiff
path: root/dhall/src/syntax/ast
diff options
context:
space:
mode:
authorNadrieril2020-03-31 19:56:02 +0100
committerNadrieril2020-03-31 19:56:02 +0100
commit6d091c29cd160ffddf870929bfb3e601fa01031a (patch)
tree031f031937718ac9c1ea8d02df37ea32ab4a75cb /dhall/src/syntax/ast
parenteecd41fe5dd155752aaaa06af02bc32f8a416ba5 (diff)
Upgrade annotate-snippets version
Diffstat (limited to 'dhall/src/syntax/ast')
-rw-r--r--dhall/src/syntax/ast/span.rs10
1 files changed, 2 insertions, 8 deletions
diff --git a/dhall/src/syntax/ast/span.rs b/dhall/src/syntax/ast/span.rs
index 153a624..79bcc52 100644
--- a/dhall/src/syntax/ast/span.rs
+++ b/dhall/src/syntax/ast/span.rs
@@ -76,18 +76,12 @@ impl Span {
/// Convert a byte idx into a string into a char idx for consumption by annotate_snippets.
fn char_idx_from_byte_idx(input: &str, idx: usize) -> usize {
- let char_idx = input
+ input
.char_indices()
.enumerate()
.find(|(_, (i, _))| *i == idx)
.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();
- let nbr_carriage_returns =
- input[..idx].chars().filter(|c| *c == '\r').count();
- char_idx + nbr_newlines - nbr_carriage_returns
+ .unwrap_or(0)
}