Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Fix some panics in edge cases. #185

Merged
merged 4 commits into from
Apr 2, 2020
Merged

Conversation

ehuss
Copy link
Collaborator

@ehuss ehuss commented Apr 2, 2020

Fixes a few cases where rustfix will panic.

  • An empty file (where there are no lines).
  • Span pointing at the end of the file.

Copy link
Member

@killercup killercup left a comment

Choose a reason for hiding this comment

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

Thanks! This looks great! How'd you find these?

@@ -160,7 +163,7 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P, mode: &str) -> Result<(), Err
))?;
let expected_suggestions =
rustfix::get_suggestions_from_json(&expected_json, &HashSet::new(), filter_suggestions)
.context("could not load expected suggesitons")?;
.context("could not load expected suggestions")?;
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch :)

// the span points to the "end" of the line. For example, a line of
// "foo\n" with a highlight_start of 5 is intended to highlight *after*
// the line. This needs to compensate since the newline has been removed
// from the text slice.
Copy link
Member

Choose a reason for hiding this comment

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

Oh? Is this a change that the newlines is not part of the text slice?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

AFAIK, rustc has never included line endings in the "text" lines.

It is somewhat unusual for spans to point past the end of the line. no_main is one of the few ways to do it. The unclosed delimiter error is the only other way I know of.

@killercup killercup merged commit e3b06b0 into rust-lang:master Apr 2, 2020
@killercup
Copy link
Member

Released as 0.5.1!

bors added a commit to rust-lang/cargo that referenced this pull request Jun 10, 2021
Update rustfix.

This updates rustfix to 0.6.0. There are a few changes since 0.5.0, the following are noticeable changes:

* rust-lang/rustfix#185 — Fix some panics in edge cases.
* rust-lang/rustfix#195 — Revert revert multiple suggestions fix

The important one is rust-lang/rustfix#195 which is necessary to handle some 2021 edition migration support. I have added a test to check that it works correctly.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants