You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use http::Uri;use std::collections::HashSet;use lazy_static::lazy_static;fnmain(){// Clippy thinks that `Uri` has interior mutability and yields a warninglet _a:HashSet<Uri> = HashSet::new();// Warning is suppressed#[allow(clippy::mutable_key_type)]let _b:HashSet<Uri> = HashSet::new();}lazy_static!{// Trying to suppress the warning
#[allow(clippy::mutable_key_type)]static ref _C:HashSet<Uri> = HashSet::new();}
if I run clippy on it, I get:
Checking playground v0.0.1 (/playground)
warning: mutable key type
--> src/main.rs:7:5
|
7 | let _a: HashSet<Uri> = HashSet::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(clippy::mutable_key_type)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mutable_key_type
warning: mutable key type
--> src/main.rs:16:20
|
16 | static ref _C: HashSet<Uri> = HashSet::new();
| ^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mutable_key_type
warning: mutable key type
--> src/main.rs:13:1
|
13 | / lazy_static! {
14 | | // Trying to suppress the warning
15 | | #[allow(clippy::mutable_key_type)]
16 | | static ref _C: HashSet<Uri> = HashSet::new();
17 | | }
| |_^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mutable_key_type
= note: this warning originates in the macro `__lazy_static_internal` (in Nightly builds, run with -Z macro-backtrace for more info)
warning: `playground` (bin "playground") generated 3 warnings
Finished dev [unoptimized + debuginfo] target(s) in 0.43s
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 the struct _C, some should go to the static _C, and some (like allow(clippy::mutable_key_type) should be scattered in the macro.
The text was updated successfully, but these errors were encountered:
use http::Uri;use std::collections::HashSet;use once_cell::sync::Lazy;fnmain(){// Clippy thinks that `Uri` has interior mutability and yields a warninglet _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.The text was updated successfully, but these errors were encountered: