Skip to content

Commit a9f64b2

Browse files
fix: refactor same-file check
Co-Authored-By: Pascal Hertleif <killercup@gmail.com>
1 parent 59b3b3e commit a9f64b2

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/cargo/ops/fix.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -402,18 +402,18 @@ fn rustfix_and_fix(
402402
// Make sure we've got a file associated with this suggestion and all
403403
// snippets point to the same file. Right now it's not clear what
404404
// we would do with multiple files.
405-
let file_name = match suggestion.solutions.get(0).and_then(|sol| sol.replacements.get(0)) {
406-
Some(s) => s.snippet.file_name.clone(),
407-
None => {
408-
trace!("rejecting as it has no solutions {:?}", suggestion);
409-
continue;
410-
}
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-
.solutions
414-
.iter()
415-
.all(|sol| sol.replacements.iter().all(|rep| rep.snippet.file_name == file_name))
416-
{
415+
416+
if !file_names.clone().all(|f| f == &file_name) {
417417
trace!("rejecting as it changes multiple files: {:?}", suggestion);
418418
continue;
419419
}

0 commit comments

Comments
 (0)