Skip to content

Commit febd008

Browse files
committed
Auto merge of #6163 - phansch:remove-one-lazy-static, r=flip1995
Remove lazy_static completely and use once_cell feature instead Follow-up to #6120 This removes the last remaining `lazy_static` usages and replaces them with `SyncLazy` from the `once_cell` feature. --- changelog: none
2 parents 18ffea0 + 7b3493c commit febd008

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@ clippy_lints = { version = "0.0.212", path = "clippy_lints" }
3434
semver = "0.10"
3535
rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"}
3636
tempfile = { version = "3.1.0", optional = true }
37-
lazy_static = "1.0"
3837

3938
[dev-dependencies]
4039
cargo_metadata = "0.11.1"
4140
compiletest_rs = { version = "0.5.0", features = ["tmp"] }
4241
tester = "0.7"
43-
lazy_static = "1.0"
4442
clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }
4543
serde = { version = "1.0", features = ["derive"] }
4644
derive-new = "0.5"

clippy_dev/src/update_lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn run(update_mode: UpdateMode) {
2929
false,
3030
update_mode == UpdateMode::Change,
3131
|| {
32-
format!("pub static ref ALL_LINTS: Vec<Lint> = vec!{:#?};", sorted_usable_lints)
32+
format!("vec!{:#?}", sorted_usable_lints)
3333
.lines()
3434
.map(ToString::to_string)
3535
.collect::<Vec<_>>()

src/driver.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(rustc_private)]
2+
#![feature(once_cell)]
23
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
34
// warn on lints, that are included in `rust-lang/rust`s bootstrap
45
#![warn(rust_2018_idioms, unused_lifetimes)]
@@ -17,9 +18,9 @@ use rustc_interface::interface;
1718
use rustc_middle::ty::TyCtxt;
1819
use rustc_tools_util::VersionInfo;
1920

20-
use lazy_static::lazy_static;
2121
use std::borrow::Cow;
2222
use std::env;
23+
use std::lazy::SyncLazy;
2324
use std::ops::Deref;
2425
use std::panic;
2526
use std::path::{Path, PathBuf};
@@ -230,13 +231,11 @@ You can use tool lints to allow or deny lints from your code, eg.:
230231

231232
const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust-clippy/issues/new";
232233

233-
lazy_static! {
234-
static ref ICE_HOOK: Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static> = {
235-
let hook = panic::take_hook();
236-
panic::set_hook(Box::new(|info| report_clippy_ice(info, BUG_REPORT_URL)));
237-
hook
238-
};
239-
}
234+
static ICE_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> = SyncLazy::new(|| {
235+
let hook = panic::take_hook();
236+
panic::set_hook(Box::new(|info| report_clippy_ice(info, BUG_REPORT_URL)));
237+
hook
238+
});
240239

241240
fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
242241
// Invoke our ICE handler, which prints the actual panic message and optionally a backtrace
@@ -295,7 +294,7 @@ fn toolchain_path(home: Option<String>, toolchain: Option<String>) -> Option<Pat
295294

296295
pub fn main() {
297296
rustc_driver::init_rustc_env_logger();
298-
lazy_static::initialize(&ICE_HOOK);
297+
SyncLazy::force(&ICE_HOOK);
299298
exit(rustc_driver::catch_with_exit_code(move || {
300299
let mut orig_args: Vec<String> = env::args().collect();
301300

src/lintlist/mod.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
//! This file is managed by `cargo dev update_lints`. Do not edit.
1+
//! This file is managed by `cargo dev update_lints`. Do not edit or format this file.
22
3-
use lazy_static::lazy_static;
3+
use std::lazy::SyncLazy;
44

55
pub mod lint;
66
pub use lint::Level;
77
pub use lint::Lint;
88
pub use lint::LINT_LEVELS;
99

10-
lazy_static! {
10+
#[rustfmt::skip]
11+
pub static ALL_LINTS: SyncLazy<Vec<Lint>> = SyncLazy::new(|| {
1112
// begin lint list, do not remove this comment, it’s used in `update_lints`
12-
pub static ref ALL_LINTS: Vec<Lint> = vec![
13+
vec![
1314
Lint {
1415
name: "absurd_extreme_comparisons",
1516
group: "correctness",
@@ -2831,6 +2832,6 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
28312832
deprecation: None,
28322833
module: "methods",
28332834
},
2834-
];
2835+
]
28352836
// end lint list, do not remove this comment, it’s used in `update_lints`
2836-
}
2837+
});

0 commit comments

Comments
 (0)