Skip to content

Cargo clippy --fix fails for thiserror #[from] macro derivations #10611

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

Open
ViddeM opened this issue Apr 8, 2023 · 1 comment
Open

Cargo clippy --fix fails for thiserror #[from] macro derivations #10611

ViddeM opened this issue Apr 8, 2023 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@ViddeM
Copy link

ViddeM commented Apr 8, 2023

Issue

cargo clippy --fix fails with a warning saying that there likely is a bug in cargo or rustc itself.
It seems that the issue is related to the #[from] macro of the thiserror crate so maybe the issue is on their end but since the warning asked for a bug-report I thought I'd follow that.

All of the reported issues seems to be instances of

error[E0277]: `?` couldn't convert the error to `ERROR_TYPE_A`
...
the trait `std::convert::From<std::result::Result<_, ERROR_TYPE_B>>` is not implemented for `ERROR_TYPE_A`

However, the code compiles normally (using cargo build) as the trait is implemented using the thiserror crates #[from] macro.

Meta

rustc --version --verbose:

rustup 1.25.2 (2023-02-04)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.70.0-nightly (23ee2af2f 2023-04-07)`
Backtrace

warning: failed to automatically apply fixes suggested by rustc to crate `accounts_rs`

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

  * src/services/email_service.rs
  * src/services/google_api_service.rs
  * src/services/reset_password_service.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]: `?` couldn't convert the error to `services::email_service::EmailError`
  --> src/services/email_service.rs:34:15
   |
34 |             })?;
   |               ^ the trait `std::convert::From<std::result::Result<_, services::google_api_service::GoogleApiError>>` is not implemented for `services::email_service::EmailError`
   |
   = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
   = help: the trait `std::convert::From<services::google_api_service::GoogleApiError>` is implemented for `services::email_service::EmailError`
   = note: required for `std::result::Result<(), services::email_service::EmailError>` to implement `std::ops::FromResidual<std::result::Result<std::convert::Infallible, std::result::Result<_, services::google_api_service::GoogleApiError>>>`

error[E0277]: `?` couldn't convert the error to `services::email_service::EmailError`
  --> src/services/email_service.rs:40:15
   |
40 |             })?;
   |               ^ the trait `std::convert::From<std::result::Result<_, services::google_api_service::GoogleApiError>>` is not implemented for `services::email_service::EmailError`
   |
   = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
   = help: the trait `std::convert::From<services::google_api_service::GoogleApiError>` is implemented for `services::email_service::EmailError`
   = note: required for `std::result::Result<(), services::email_service::EmailError>` to implement `std::ops::FromResidual<std::result::Result<std::convert::Infallible, std::result::Result<_, services::google_api_service::GoogleApiError>>>`

error[E0277]: `?` couldn't convert the error to `services::reset_password_service::ResetPasswordError`
  --> src/services/reset_password_service.rs:55:11
   |
55 |         })?;
   |           ^ the trait `std::convert::From<std::result::Result<_, services::reset_password_service::ResetPasswordError>>` is not implemented for `services::reset_password_service::ResetPasswordError`
   |
   = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
   = help: the following other types implement trait `std::convert::From<T>`:
             <services::reset_password_service::ResetPasswordError as std::convert::From<services::email_service::EmailError>>
             <services::reset_password_service::ResetPasswordError as std::convert::From<sqlx::Error>>
             <services::reset_password_service::ResetPasswordError as std::convert::From<util::accounts_error::AccountsError>>
   = note: required for `std::result::Result<(), services::reset_password_service::ResetPasswordError>` to implement `std::ops::FromResidual<std::result::Result<std::convert::Infallible, std::result::Result<_, services::reset_password_service::ResetPasswordError>>>`

error[E0277]: `?` couldn't convert the error to `services::reset_password_service::ResetPasswordError`
   --> src/services/reset_password_service.rs:166:11
    |
166 |         })?;
    |           ^ the trait `std::convert::From<std::result::Result<_, services::reset_password_service::ResetPasswordError>>` is not implemented for `services::reset_password_service::ResetPasswordError`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `std::convert::From<T>`:
              <services::reset_password_service::ResetPasswordError as std::convert::From<services::email_service::EmailError>>
              <services::reset_password_service::ResetPasswordError as std::convert::From<sqlx::Error>>
              <services::reset_password_service::ResetPasswordError as std::convert::From<util::accounts_error::AccountsError>>
    = note: required for `std::result::Result<(), services::reset_password_service::ResetPasswordError>` to implement `std::ops::FromResidual<std::result::Result<std::convert::Infallible, std::result::Result<_, services::reset_password_service::ResetPasswordError>>>`

error[E0277]: `?` couldn't convert the error to `services::google_api_service::GoogleApiError`
  --> src/services/google_api_service.rs:94:7
   |
94 |     })?;
   |       ^ the trait `std::convert::From<std::result::Result<_, services::google_api_service::GoogleApiError>>` is not implemented for `services::google_api_service::GoogleApiError`
   |
   = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
   = help: the following other types implement trait `std::convert::From<T>`:
             <services::google_api_service::GoogleApiError as std::convert::From<jwt::Error>>
             <services::google_api_service::GoogleApiError as std::convert::From<openssl::error::ErrorStack>>
             <services::google_api_service::GoogleApiError as std::convert::From<reqwest::Error>>
   = note: required for `std::result::Result<std::string::String, services::google_api_service::GoogleApiError>` to implement `std::ops::FromResidual<std::result::Result<std::convert::Infallible, std::result::Result<_, services::google_api_service::GoogleApiError>>>`

error[E0277]: `?` couldn't convert the error to `services::google_api_service::GoogleApiError`
   --> src/services/google_api_service.rs:158:11
    |
158 |         })?;
    |           ^ the trait `std::convert::From<std::result::Result<_, services::google_api_service::GoogleApiError>>` is not implemented for `services::google_api_service::GoogleApiError`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `std::convert::From<T>`:
              <services::google_api_service::GoogleApiError as std::convert::From<jwt::Error>>
              <services::google_api_service::GoogleApiError as std::convert::From<openssl::error::ErrorStack>>
              <services::google_api_service::GoogleApiError as std::convert::From<reqwest::Error>>
    = note: required for `std::result::Result<(), services::google_api_service::GoogleApiError>` to implement `std::ops::FromResidual<std::result::Result<std::convert::Infallible, std::result::Result<_, services::google_api_service::GoogleApiError>>>`

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0277`.
Original diagnostics will follow.

This is followed by the standard cargo clippy output.

If helpful, the project in question is https://github.com/viddem/accounts-rs and the output above is on commit d9b0694.

@ViddeM ViddeM added the C-bug Category: Clippy is not doing the correct thing label Apr 8, 2023
@jyn514
Copy link
Member

jyn514 commented Apr 8, 2023

@matthiaskrgr could you transfer this to rust-clippy please?

cc rust-lang/cargo#11877

@matthiaskrgr matthiaskrgr transferred this issue from rust-lang/rust Apr 8, 2023
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
Projects
None yet
Development

No branches or pull requests

2 participants