You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
trace!("rejecting as it spans multiple files {:?}", suggestion);
continue;
}
checks that the suggestion.snippets point to the same file and range. This was a conservative approach as the edition lints are not doing anything fancy here:
Looking at how I could change the check, I have a doubt about the overlapping requirement for solutions (s.line_range == range). While having all the solutions on the same file is fine, for the unused_imports lint I need to have multiple solutions changing different parts of the line:
// Only HashSet is used here
use std::collections::{HashMap, HashSet, VecDeque};
^^^^^^^^^ ^^^^^^^^^^
\-- removed --/
Is making sure all solutions are on the same file enough?
I'm actually not sure what the range requirement was supposed to solve. Checking that the suggestions are in the same file important as we apply the changes file by file. Checking that the ranges are all the same range is saying "skip all suggestions with multiple replacements", if I read the code correctly. This is a case that might previously have helped but is now actively filtering out the suggestions we care about, it seems.
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 @killercupfixes#6401
@pietroalbini pointed out an example where cargo-fix was too conservative and skipped a valid replacement:
The problem is that this code
cargo/src/cargo/ops/fix.rs
Lines 412 to 419 in 41a7e15
checks that the
suggestion.snippets
point to the same file and range. This was a conservative approach as the edition lints are not doing anything fancy here:cargo/src/cargo/ops/fix.rs
Lines 402 to 404 in 41a7e15
The
unused_imports
lints however goes out of its way to only yield one replacements for a suggestion with two snippets.It seems to me that changing the check to not be based on snippets that don't have replacements, but to look at the
solutions
would fix this.cc @alexcrichton who I believe wrote the original code
trace log for the run that produced the above screenshot
Formatted version of suggestion we parse
The text was updated successfully, but these errors were encountered: