-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
"unused #[macro_use]
import" false positive in libs and unit-tests
#44342
Comments
cc @est31 as the one worked on Add lint for unused macros PR |
In fact, problem is somewhat different and more generic: unused lint doesn't see anything that is used inside of I've run into this with a local macro as well (which initially seemed different, but now I think is the same issue): https://play.rust-lang.org/?gist=0c4a2ca1e118674b9d6666e58a37da97&version=stable // Produces warning: unused macro definition
macro_rules! assert_ok {
($s:expr, $res:expr, $rest:expr) => {
assert_eq!($s, Ok(($res, $rest)))
};
}
#[test]
fn test() {
assert_ok!(Ok(1, ""), 1, "");
}
fn main() {}
UPD: Actually it does help to suppress the warning https://play.rust-lang.org/?gist=0bdf3930b49f0835db08ed351a405b7e&version=stable, for some reason that didn't work locally. @hcpl Try adding |
Adding |
I have the issue, I need the crate always (for test and normal config), but I only need the #[macro_use] in the test config. If I use:
then I get the warning during compile (non-test config compile I guess). I tried to use #[cfg(test)] but that then removes the extern crate for the normal config so, I had to use this:
|
@andrewdavidmackenzie Doesn't seem same as this issue, but have you tried |
should do it |
It seems like this is not a bug -- it is unfortunate that "unused" lints and so forth fire even when other configurations may use those things, but it is not specific to this lint and would be rather difficult to truly fix. Closing for now. |
this the macro in serde_json is used only in test, remove it for non test. solution found [here)(rust-lang/rust#44342 (comment))
It doesn't recognize that
assert_eq!
frompretty_assertions
has shadowed the standard one.Code
src/lib.rs
:Command and output
Configuration
Note that
cargo run
with equivalentsrc/main.rs
:works fine:
But this
src/main.rs
:will trigger the warning too:
The text was updated successfully, but these errors were encountered: