Open yeputons opened 2 years ago
Possible workaround: use once_cell::sync::Lazy
:
use http::Uri;
use std::collections::HashSet;
use once_cell::sync::Lazy;
fn main() {
// Clippy thinks that `Uri` has interior mutability and yields a warning
let _a: HashSet<Uri> = HashSet::new();
// Warning is suppressed
#[allow(clippy::mutable_key_type)]
let _b: HashSet<Uri> = HashSet::new();
}
// Trying to suppress the warning
#[allow(clippy::mutable_key_type)]
static _C: Lazy<HashSet<Uri>> = Lazy::new(HashSet::new);
Consider the following example:
if I run clippy on it, I get:
So, the warning is not suppressed on
_a
and is suppressed on_b
as expected. However, the attribute on_C
does nothing. Moreover, two warnings are yielded, not just one.Looking at the expansion (courtesy of IntelliJ's Rust plugin, so may be off):
It seems that the attribute is attached to the
struct _C
, but warnings are actually emitted by some code in the macro. I'm not really sure what is the proper fix here: I suspect some attribute should really go to thestruct _C
, some should go to thestatic _C
, and some (likeallow(clippy::mutable_key_type)
should be scattered in the macro.