-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Spurious "useless lint attribute" warning #1938
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
Comments
Question: why do you want to ignore an unused This is a known limitation of the lint (see https://rust-lang-nursery.github.io/rust-clippy/master/index.html#useless_attribute ), but as the limitation states, it's easier to remove the unused import than to add an |
My crate exports macros that, internally, use
In my case, I actually need the import. |
That sounds more like a rustc bug to me. Have you reported this upstream? |
I don't think it's a rustc bug. Maybe I'm missing something though. Here's the full file if you're curious. |
Ah... your macro is unusable within crates that don't have #[macro_use]
extern crate lazy_static; So I suggest to move the The trick mentioned in https://gist.github.com/joshlf/87783078dad1d888a321db50da5d4097#file-lib-rs-L474 kinda works but is hacky imo. The solution of moving the crate import into the macro itself is also used by |
I'm not sure that it would work. My concern is that since |
Oh, and more problematically, putting |
This is a major pain with rustc gives a spurious unused crate error for When we disable that lint, Which brings us to this mess:
|
The |
You have to do that anyway as far as I can see.
That has been fixed in rustc |
Nah, I'm able to do: #[doc(hidden)]
pub use lazy_static::*;
Good to know! |
In that case the lint |
Another example of a false positive case: I use The solution is to annotate the Whether you consider this a Rustc problem or not, it's pretty unambiguous that the "why this is bad" description is wrong isn't it?
Having an |
BTW you can simply annotate it with |
@sinkuu Thanks! I'd basically solved it with: #[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
#[allow(unused_imports)]
#[macro_use]
extern create serde_json; But that seems better. |
I have a lot of code using cfg_if! {
if #[cfg(all(target_arch = "arm", target_feature = "v7", target_feature = "neon"))] {
// Do something differently
extern crate coresimd;
#[allow(unused_import)]
use coresimd::arch;
} else {
// Add the import because some other target_arch/target_feature combinations
// need it, but not all:
#[allow(unused_import)]
use core::arch;
}
} |
@gnzlbg |
- Disabled the clippy::std_instead_of_core lint for the std module due to a false positive on std::env, which is due to the following bug: rust-lang/rust-clippy#12438 The fix had to be applied globally otherwise it triggered a "useless lint attribute" warning, which may be another bug! rust-lang/rust-clippy#1938
Given the following code:
cargo build
produces the following warning:If we then add
#[allow(unused_imports)]
:then
cargo build
produces no warnings. However, if we runcargo clippy
on this code, we get a "useless lint attribute" warning:The text was updated successfully, but these errors were encountered: