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

when rustc suggests alternative solutions, rustfix will apply none of them #104910

Open
matthiaskrgr opened this issue Nov 25, 2022 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

Given the following code:
src/test/ui/lint/let_underscore/let_underscore_drop.rs

// check-pass
#![warn(let_underscore_drop)]

struct NontrivialDrop;

impl Drop for NontrivialDrop {
    fn drop(&mut self) {
        println!("Dropping!");
    }
}

fn main() {
    let _ = NontrivialDrop; //~WARNING non-binding let on a type that implements `Drop`
}

The current output is:

warning: non-binding let on a type that implements `Drop`
  --> src/main.rs:13:5
   |
13 |     let _ = NontrivialDrop; //~WARNING non-binding let on a type that implements `Drop`
   |     ^^^^^^^^^^^^^^^^^^^^^^^
   |
note: the lint level is defined here
  --> src/main.rs:2:9
   |
2  | #![warn(let_underscore_drop)]
   |         ^^^^^^^^^^^^^^^^^^^
help: consider binding to an unused variable to avoid immediately dropping the value
   |
13 |     let _unused = NontrivialDrop; //~WARNING non-binding let on a type that implements `Drop`
   |         ~~~~~~~
help: consider immediately dropping the value
   |
13 |     drop(NontrivialDrop); //~WARNING non-binding let on a type that implements `Drop`
   |     ~~~~~              +

It's great that we can suggest several solutions here BUT this will prevent rustfix from applying ANY of them 😅

The full error message was:

> Could not replace range 181...188 in file -- maybe parts of it were already replaced?

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

I wonder if we can be more clever about this, perhaps flags the first one somehow and and tell rustfix "apply this, and only if that fails to compile, try this other suggestion" ?

@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 25, 2022
@jruderman
Copy link
Contributor

Related to #53934

@jyn514 jyn514 added the D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. label Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-diagnostic-infra Diagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants