Skip to content

Commit f856ccf

Browse files
tamaroningrizsotto
authored andcommitted
rust: replace lazy_static with LazyLock
1 parent 2dec5ce commit f856ccf

File tree

6 files changed

+48
-55
lines changed

6 files changed

+48
-55
lines changed

rust/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ resolver = "2"
99
[workspace.dependencies]
1010
thiserror = "1.0"
1111
anyhow = "1.0"
12-
lazy_static = { version = "1.5", default-features = false }
1312
serde = { version = "1.0", default-features = false, features = ["derive"] }
1413
serde_json = { version = "1.0", default-features = false, features = ["std"] }
1514
serde_yml = "0.0"

rust/bear/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ path = "src/bin/wrapper.rs"
2626
[dependencies]
2727
thiserror.workspace = true
2828
anyhow.workspace = true
29-
lazy_static.workspace = true
3029
serde.workspace = true
3130
serde_json.workspace = true
3231
serde_yml.workspace = true

rust/bear/src/semantic/interpreters/gcc.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ impl Interpreter for Gcc {
4343
}
4444

4545
mod internal {
46-
use lazy_static::lazy_static;
4746
use nom::{error::ErrorKind, IResult};
4847
use regex::Regex;
4948
use std::path::PathBuf;
@@ -194,16 +193,17 @@ mod internal {
194193
todo!()
195194
}
196195

197-
lazy_static! {
196+
static COMPILER_REGEX: std::sync::LazyLock<Regex> = std::sync::LazyLock::new(|| {
198197
// - cc
199198
// - c++
200199
// - cxx
201200
// - CC
202201
// - mcc, gcc, m++, g++, gfortran, fortran
203202
// - with prefixes like: arm-none-eabi-
204203
// - with postfixes like: -7.0 or 6.4.0
205-
static ref COMPILER_REGEX: Regex = Regex::new(
206-
r"(^(cc|c\+\+|cxx|CC|(([^-]*-)*([mg](cc|\+\+)|[g]?fortran)(-?\d+(\.\d+){0,2})?))$)"
207-
).unwrap();
208-
}
204+
Regex::new(
205+
r"(^(cc|c\+\+|cxx|CC|(([^-]*-)*([mg](cc|\+\+)|[g]?fortran)(-?\d+(\.\d+){0,2})?))$)",
206+
)
207+
.unwrap()
208+
});
209209
}

rust/bear/src/semantic/interpreters/generic.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ impl Interpreter for Generic {
6464
mod test {
6565
use std::collections::HashMap;
6666

67-
use lazy_static::lazy_static;
68-
6967
use crate::{vec_of_pathbuf, vec_of_strings};
7068

7169
use super::*;
@@ -126,9 +124,7 @@ mod test {
126124
assert_eq!(Recognition::Unknown, SUT.recognize(&input));
127125
}
128126

129-
lazy_static! {
130-
static ref SUT: Generic = Generic {
131-
executables: vec_of_pathbuf!["/usr/bin/something"].into_iter().collect()
132-
};
133-
}
127+
static SUT: std::sync::LazyLock<Generic> = std::sync::LazyLock::new(|| Generic {
128+
executables: vec_of_pathbuf!["/usr/bin/something"].into_iter().collect(),
129+
});
134130
}

rust/bear/src/semantic/interpreters/matchers/source.rs

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// SPDX-License-Identifier: GPL-3.0-or-later
22

3-
use lazy_static::lazy_static;
43
use std::collections::HashSet;
54

65
#[cfg(target_family = "unix")]
@@ -27,39 +26,38 @@ pub fn looks_like_a_source_file(argument: &str) -> bool {
2726
false
2827
}
2928

30-
lazy_static! {
31-
static ref EXTENSIONS: HashSet<&'static str> = {
32-
HashSet::from([
33-
// header files
34-
"h", "hh", "H", "hp", "hxx", "hpp", "HPP", "h++", "tcc",
35-
// C
36-
"c", "C",
37-
// C++
38-
"cc", "CC", "c++", "C++", "cxx", "cpp", "cp",
39-
// CUDA
40-
"cu",
41-
// ObjectiveC
42-
"m", "mi", "mm", "M", "mii",
43-
// Preprocessed
44-
"i", "ii",
45-
// Assembly
46-
"s", "S", "sx", "asm",
47-
// Fortran
48-
"f", "for", "ftn",
49-
"F", "FOR", "fpp", "FPP", "FTN",
50-
"f90", "f95", "f03", "f08",
51-
"F90", "F95", "F03", "F08",
52-
// go
53-
"go",
54-
// brig
55-
"brig",
56-
// D
57-
"d", "di", "dd",
58-
// Ada
59-
"ads", "abd"
60-
])
61-
};
62-
}
29+
#[rustfmt::skip]
30+
static EXTENSIONS: std::sync::LazyLock<HashSet<&'static str>> = std::sync::LazyLock::new(|| {
31+
HashSet::from([
32+
// header files
33+
"h", "hh", "H", "hp", "hxx", "hpp", "HPP", "h++", "tcc",
34+
// C
35+
"c", "C",
36+
// C++
37+
"cc", "CC", "c++", "C++", "cxx", "cpp", "cp",
38+
// CUDA
39+
"cu",
40+
// ObjectiveC
41+
"m", "mi", "mm", "M", "mii",
42+
// Preprocessed
43+
"i", "ii",
44+
// Assembly
45+
"s", "S", "sx", "asm",
46+
// Fortran
47+
"f", "for", "ftn",
48+
"F", "FOR", "fpp", "FPP", "FTN",
49+
"f90", "f95", "f03", "f08",
50+
"F90", "F95", "F03", "F08",
51+
// go
52+
"go",
53+
// brig
54+
"brig",
55+
// D
56+
"d", "di", "dd",
57+
// Ada
58+
"ads", "abd",
59+
])
60+
});
6361

6462
#[cfg(test)]
6563
mod test {

rust/bear/tests/intercept.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use bear::intercept::*;
77
mod test {
88
use super::*;
99
use crossbeam_channel::bounded;
10-
use lazy_static::lazy_static;
1110
use std::collections::HashMap;
1211
use std::io::Cursor;
1312
use std::path::PathBuf;
@@ -77,8 +76,8 @@ mod test {
7776
}
7877
}
7978

80-
lazy_static! {
81-
static ref ENVELOPES: Vec<Envelope> = vec![
79+
static ENVELOPES: std::sync::LazyLock<Vec<Envelope>> = std::sync::LazyLock::new(|| {
80+
vec![
8281
Envelope {
8382
rid: ReporterId::new(),
8483
timestamp: fixtures::timestamp(),
@@ -124,9 +123,11 @@ mod test {
124123
},
125124
},
126125
},
127-
];
128-
static ref EVENTS: Vec<Event> = ENVELOPES.iter().map(|e| e.event.clone()).collect();
129-
}
126+
]
127+
});
128+
129+
static EVENTS: std::sync::LazyLock<Vec<Event>> =
130+
std::sync::LazyLock::new(|| ENVELOPES.iter().map(|e| e.event.clone()).collect());
130131
}
131132

132133
mod fixtures {

0 commit comments

Comments
 (0)