Skip to content

Commit

Permalink
Merge pull request #193 from oli-obk/multi_file_suggs
Browse files Browse the repository at this point in the history
Multi file suggs
  • Loading branch information
oli-obk authored Jan 24, 2024
2 parents addbd2c + f53f3f6 commit f4a4242
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

* report an error instead of panicking when encountering a suggestion that does not belong to the main file.

### Changed

* crate-private span handling was passed off to the `spanned` crate, improving some diagnostics along the way.
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,14 @@ fn run_rustfix(
if suggestions.is_empty() {
None
} else {
let path_str = path.display().to_string();
for sugg in &suggestions {
for snip in &sugg.snippets {
if snip.file_name != path_str {
return Some(Err(anyhow::anyhow!("cannot apply suggestions for `{}` since main file is `{path_str}`. Please use `//@no-rustfix` to disable rustfix", snip.file_name)));
}
}
}
Some(rustfix::apply_suggestions(
&std::fs::read_to_string(path).unwrap(),
&suggestions,
Expand Down

0 comments on commit f4a4242

Please sign in to comment.