Skip to content

Commit

Permalink
Auto merge of #6402 - pietroalbini:fix-cargofix, r=alexcrichton
Browse files Browse the repository at this point in the history
Only ensure solutions are in the same file in cargo fix

This PR changes `cargo fix` to avoid rejecting machine-applicable lints with multiple suggestions. Instead, now it only checks the solutions are in the same file.

I don't know how to write a test for this, since no lint in rustc relies on the new behavior and the existing `cargo fix` tests just invoke lints in rustc. Any idea on that would be appreciated.

r? @alexcrichton
cc @killercup
fixes #6401
  • Loading branch information
bors committed Dec 10, 2018
2 parents 28fb200 + a9f64b2 commit e074068
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,21 +400,21 @@ fn rustfix_and_fix(
for suggestion in suggestions {
trace!("suggestion");
// Make sure we've got a file associated with this suggestion and all
// snippets point to the same location. Right now it's not clear what
// we would do with multiple locations.
let (file_name, range) = match suggestion.snippets.get(0) {
Some(s) => (s.file_name.clone(), s.line_range),
None => {
trace!("rejecting as it has no snippets {:?}", suggestion);
continue;
}
// snippets point to the same file. Right now it's not clear what
// we would do with multiple files.
let file_names = suggestion.solutions.iter()
.flat_map(|s| s.replacements.iter())
.map(|r| &r.snippet.file_name);

let file_name = if let Some(file_name) = file_names.clone().next() {
file_name.clone()
} else {
trace!("rejecting as it has no solutions {:?}", suggestion);
continue;
};
if !suggestion
.snippets
.iter()
.all(|s| s.file_name == file_name && s.line_range == range)
{
trace!("rejecting as it spans multiple files {:?}", suggestion);

if !file_names.clone().all(|f| f == &file_name) {
trace!("rejecting as it changes multiple files: {:?}", suggestion);
continue;
}

Expand Down

0 comments on commit e074068

Please sign in to comment.