-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
cargo fix
: Panic with "Cannot replace slice of data that was already replaced"
#13030
Comments
FWIW, there's some existing code in rustc that references this panic: https://github.com/rust-lang/rust/blob/f103b2969b0088953873dc1ac92eb3387c753596/compiler/rustc_builtin_macros/src/format.rs#L323-L330 |
Diagnostics with multiple exclusive options shouldn't be marked as MachineApplicable (as rustfix obviously can't handle them). To handle this, rustfix would need to gain the ability to provide a user-interactive multiple-choice UI for choosing which fix to apply. There is some discussion of something like this in #13028. It is feasible, though I personally don't think it is very valuable. I prefer to interact within my editor and apply suggestions by clicking quick-fix buttons. That means you don't have to go out and use a separate tool, and makes it easier to see the changes in context, and is generally faster (for me). |
Hi @ehuss, thanks for your quick reply! I would have responded sooner but I missed your message :) The multiple exclusive options actually are not marked as MachineApplicable. They were marked as MaybeIncorrect and then later Unspecified, but I'm still getting the panic. Any idea why this is happening? |
If you mean by a UI test, then you'll want to remove the |
Ah, I didn't realize that it applied suggestions indiscriminately! I moved the exclusive suggestions to another test since otherwise the generated Is this panic still considered a bug (and thus I should leave the issue open) or is it considered a sign of something wrong with rustc's output that is thus not a rustfix bug? |
I'd leave it open. Even though these types of suggestions aren't currently supported, it probably shouldn't panic. |
cargo fix
: Panic with "Cannot replace slice of data that was already replaced"
I have a PR to add a new suggestion to rustc: rust-lang/rust#88672. It uses
Diagnostic::multipart_suggestions
since there are multiple ways for the user to change their code. These multiple suggestions are exclusive since they modify the same code.However, rustfix is panicking when I use
run-rustfix
in a test: "Cannot replace slice of data that was already replaced".The relevant code in my PR is here: https://github.com/rust-lang/rust/blob/6a89e97ab14cd4c6be70b47fd139c87fd90150b7/compiler/rustc_parse/src/parser/diagnostics.rs#L226-L234
and here: https://github.com/rust-lang/rust/blob/6a89e97ab14cd4c6be70b47fd139c87fd90150b7/compiler/rustc_parse/src/parser/diagnostics.rs#L1272-L1277
I'm not sure how to fix this problem in rustfix, but I'm willing to try with some mentoring :)
The text was updated successfully, but these errors were encountered: