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

cargo clippy --fix generated broken code #9583

Open
rbtcollins opened this issue Oct 3, 2022 · 3 comments
Open

cargo clippy --fix generated broken code #9583

rbtcollins opened this issue Oct 3, 2022 · 3 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@rbtcollins
Copy link

Output from clippy.

after fixes were automatically applied the compiler reported errors within these files:

  * examples/threads.rs

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

The following errors were reported:
error[E0277]: the `?` operator can only be used in an async block that returns `Result` or `Option` (or another type that implements `std::ops::FromResidual`)
  --> examples/threads.rs:61:32
   |
60 |       rt.block_on(async {
   |  _______________________-
61 | |         client.register().await?
   | |                                ^ cannot use the `?` operator in an async block that returns `()`
62 | |     })?;
   | |_____- this function should return `Result` or `Option` to accept `?`
   |
   = help: the trait `std::ops::FromResidual<std::result::Result<std::convert::Infallible, std::boxed::Box<dyn std::error::Error + std::marker::Send + std::marker::Sync>>>` is not implemented for `()`

error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try`
  --> examples/threads.rs:60:5
   |
60 | /     rt.block_on(async {
61 | |         client.register().await?
62 | |     })?;
   | |_______^ the `?` operator cannot be applied to type `()`
   |
   = help: the trait `std::ops::Try` is not implemented for `()`

error: aborting due to 2 previous errors

I would be happy if either the lint didn't fire, or if clippy fixed things with code that works.

Meta

The same error occurs with nightly.

rustc --version --verbose:

rustc 1.64.0 (a55dd71d5 2022-09-19)
rustc 1.66.0-nightly (57f097ea2 2022-10-01)
@rbtcollins rbtcollins added the C-bug Category: Clippy is not doing the correct thing label Oct 3, 2022
@matthiaskrgr matthiaskrgr transferred this issue from rust-lang/rust Oct 3, 2022
@Alexendoo
Copy link
Member

Could you share the output of running cargo clippy without --fix, or the code this occurred on?

@rbtcollins
Copy link
Author

rbtcollins commented Oct 3, 2022

The allow was added after this.

    rt.block_on(async {
        if let Err(e) = client.register().await {
            Err(e)
        } else {
            Ok(())
        }
    })?;

for permanence

@dswij dswij added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

3 participants