-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing
Description
Summary
When using a Lazy
type from another crate (e.g. lazy_regex
), the non_std_lazy_statics
lint is triggered, but fails to be recognised when it is expect
ed. expect
ing the lint seems to work fine when using e.g. lazy_static::lazy_static!
, but when the offending item is in the type position it doesn't like it.
Clippy version: clippy 0.1.88 (4824c2bb74 2025-05-02)
Reproducer
Take the following code:
#![warn(clippy::non_std_lazy_statics)]
use lazy_regex::{lazy_regex, Lazy};
use regex::Regex;
static REGEX: Lazy<Regex> = lazy_regex!(r#"ab*"#);
pub fn matches() -> bool {
(*REGEX).is_match("ab")
}
Running cargo clippy
gives the following output, which makes sense:
warning: this type has been superseded by `LazyLock` in the standard library
--> src/lib.rs:6:15
|
6 | static REGEX: Lazy<Regex> = lazy_regex!(r#"ab*"#);
| ^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#non_std_lazy_statics
note: the lint level is defined here
--> src/lib.rs:1:9
|
1 | #![warn(clippy::non_std_lazy_statics)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: use `std::sync::LazyLock` instead
|
6 - static REGEX: Lazy<Regex> = lazy_regex!(r#"ab*"#);
6 + static REGEX: std::sync::LazyLock<Regex> = std::sync::LazyLock::new;
|
Adding #[expect(clippy::non_std_lazy_statics)]
:
New code
#![warn(clippy::non_std_lazy_statics)]
use lazy_regex::{lazy_regex, Lazy};
use regex::Regex;
#[expect(clippy::non_std_lazy_statics)]
static REGEX: Lazy<Regex> = lazy_regex!(r#"ab*"#);
pub fn matches() -> bool {
(*REGEX).is_match("ab")
}
And cargo clippy
now says:
warning: this type has been superseded by `LazyLock` in the standard library
--> src/lib.rs:7:16
|
7 | static REGEX: Lazy<Regex> = lazy_regex!(r#"ab*"#);
| ^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#non_std_lazy_statics
note: the lint level is defined here
--> src/lib.rs:1:9
|
1 | #![warn(clippy::non_std_lazy_statics)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: use `std::sync::LazyLock` instead
|
7 - static REGEX: Lazy<Regex> = lazy_regex!(r#"ab*"#);
7 + static REGEX: std::sync::LazyLock<Regex> = std::sync::LazyLock::new;
|
warning: this lint expectation is unfulfilled
--> src/lib.rs:6:10
|
6 | #[expect(clippy::non_std_lazy_statics)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
So, the #[expect(...)]
is not suppressing the lint correctly.
Version
rustc 1.88.0-nightly (4824c2bb7 2025-05-02)
binary: rustc
commit-hash: 4824c2bb7445cb2478aab0190c268c939d77a0f6
commit-date: 2025-05-02
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing