Skip to content

Commit e074068

Browse files
committed
Auto merge of #6402 - pietroalbini:fix-cargofix, r=alexcrichton
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
2 parents 28fb200 + a9f64b2 commit e074068

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/cargo/ops/fix.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -400,21 +400,21 @@ fn rustfix_and_fix(
400400
for suggestion in suggestions {
401401
trace!("suggestion");
402402
// Make sure we've got a file associated with this suggestion and all
403-
// snippets point to the same location. Right now it's not clear what
404-
// we would do with multiple locations.
405-
let (file_name, range) = match suggestion.snippets.get(0) {
406-
Some(s) => (s.file_name.clone(), s.line_range),
407-
None => {
408-
trace!("rejecting as it has no snippets {:?}", suggestion);
409-
continue;
410-
}
403+
// snippets point to the same file. Right now it's not clear what
404+
// we would do with multiple files.
405+
let file_names = suggestion.solutions.iter()
406+
.flat_map(|s| s.replacements.iter())
407+
.map(|r| &r.snippet.file_name);
408+
409+
let file_name = if let Some(file_name) = file_names.clone().next() {
410+
file_name.clone()
411+
} else {
412+
trace!("rejecting as it has no solutions {:?}", suggestion);
413+
continue;
411414
};
412-
if !suggestion
413-
.snippets
414-
.iter()
415-
.all(|s| s.file_name == file_name && s.line_range == range)
416-
{
417-
trace!("rejecting as it spans multiple files {:?}", suggestion);
415+
416+
if !file_names.clone().all(|f| f == &file_name) {
417+
trace!("rejecting as it changes multiple files: {:?}", suggestion);
418418
continue;
419419
}
420420

0 commit comments

Comments
 (0)