Skip to content

Commit

Permalink
fix: refactor same-file check
Browse files Browse the repository at this point in the history
Co-Authored-By: Pascal Hertleif <killercup@gmail.com>
  • Loading branch information
pietroalbini and killercup committed Dec 9, 2018
1 parent 59b3b3e commit a9f64b2
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,18 +402,18 @@ fn rustfix_and_fix(
// Make sure we've got a file associated with this suggestion and all
// snippets point to the same file. Right now it's not clear what
// we would do with multiple files.
let file_name = match suggestion.solutions.get(0).and_then(|sol| sol.replacements.get(0)) {
Some(s) => s.snippet.file_name.clone(),
None => {
trace!("rejecting as it has no solutions {:?}", suggestion);
continue;
}
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
.solutions
.iter()
.all(|sol| sol.replacements.iter().all(|rep| rep.snippet.file_name == file_name))
{

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

0 comments on commit a9f64b2

Please sign in to comment.