Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix how warnings/errors are displayed to avoid a crash #2251

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion forc-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole function is hard to read. Is end_ix an index or a length? Adding two indices together doesn't make sense does it? I can't tell what's going on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know what? I'm going to study that whole function tomorrow and rewrite it. This change is a bandaid fix and will probably lead to more issues in the future.

}

const LOG_FILTER: &str = "RUST_LOG";
Expand Down