From 924d3e3c251ae35f431230857e9c6a728831d73a Mon Sep 17 00:00:00 2001 From: Mohammad Fawaz Date: Wed, 6 Jul 2022 16:19:32 -0400 Subject: [PATCH] Fix display of warnings --- forc-util/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/forc-util/src/lib.rs b/forc-util/src/lib.rs index 48490319827..310096cbbbc 100644 --- a/forc-util/src/lib.rs +++ b/forc-util/src/lib.rs @@ -407,7 +407,10 @@ fn construct_window<'a>( *start_ix -= std::cmp::min(calculated_start_ix, *start_ix); *end_ix -= std::cmp::min(calculated_start_ix, *end_ix); start.line = lines_to_start_of_snippet; - &input[calculated_start_ix..calculated_end_ix] + + // The length of input must be at least as big as *end_ix. This is required by the + // annotate_snippets library + &input[calculated_start_ix..std::cmp::max(calculated_start_ix + *end_ix, calculated_end_ix)] } const LOG_FILTER: &str = "RUST_LOG";