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
Many "unused imports" warning occurs #343
Comments
|
Please tell me what version of rustc you are using, and the exact warning you see. |
every warning is same |
|
I don't understand. What code corresponds to that warning? I was expecting to see something about |
|
Ok, I can't upload all codes here but it's like this. #[mockall::automock]
pub mod Sth {
use crate::somerecord;
use crate::someerror;
use crate::somepool;
use std::convert::TryInto; // <- this causes unused imports warning.
use uuid::Uuid;
pub async fn find_by_id(id: Uuid) -> Result<somerecord, someerror> {
let row = sqlx::query("SELECT * FROM sth WHERE id = $1::uuid")
.bind(id)
.fetch_one(somepool.get().unwrap())
.await
.map_err::<someerror, _>(Into::into)?;
Ok(row.try_into()?)
}
} |
|
And that code produces what warning? |
|
This one. warning: unused import: |
|
Should be easy to suppress. The generated mock module needs those imports, in case they're used by the mock functions' signatures. But in this case, they're only used by the bodies, so the import isn't used. Suppressing the warning in mockall is the correct solution. |
|
Ah yes that's what I'm doing currently with allow unused_imports. Thank you for replying. It will be great if that causes no warning without suppressing. |
|
Reopening, because Mockall should suppress this warning itself. |
A user might import a type or trait into an automocked module. Mockall must emit those same imports in the generated code, because the imported type might be used by the signature of a mocked method. But if it's only used by a body, then it will trigger an unused_import warning. So Mockall must suppress those. Fixes #343
|
@ulwlu could you please test your crate against the branch in the linked PR? |
|
Sure, now I am working but will try in a day. |
|
I tried with the cargo.toml below, and all errors are gone! thx!!! |
|
Hi do you plan to release this one in next version...? |
|
@ulwlu done! |
|
Thank you very much!! And thank you for this great mocking library again. |
thank you for this great library.
v0.10.2
Like example below,
In this case, TryInto surely is used but warns
unused imports. Not only this, but also like below.I think this related to https://github.com/asomers/mockall/pull/54/files, but I can't find where to fix.
The text was updated successfully, but these errors were encountered: