Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only ensure solutions are in the same file in cargo fix #6402

Merged
merged 2 commits into from
Dec 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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