Skip to content

Commit 3151ad5

Browse files
authored
Rollup merge of #124475 - GKFX:more-dependency-pruning, r=oli-obk
Remove direct dependencies on lazy_static, once_cell and byteorder The relevant functionality of all three crates is now available and stable in the standard library, i.e. `std::sync::OnceLock` and `{integer}::to_le_bytes`. I think waiting for `LazyLock` (#109736) would give marginally more concise code, but not by much.
2 parents 4355749 + 8aa3c59 commit 3151ad5

File tree

20 files changed

+71
-96
lines changed

20 files changed

+71
-96
lines changed

Cargo.lock

-7
Original file line numberDiff line numberDiff line change
@@ -2113,7 +2113,6 @@ dependencies = [
21132113
"fs-err",
21142114
"getopts",
21152115
"jsonpath_lib",
2116-
"once_cell",
21172116
"regex",
21182117
"serde_json",
21192118
"shlex",
@@ -2232,7 +2231,6 @@ name = "linkchecker"
22322231
version = "0.1.0"
22332232
dependencies = [
22342233
"html5ever",
2235-
"once_cell",
22362234
"regex",
22372235
]
22382236

@@ -2491,7 +2489,6 @@ dependencies = [
24912489
"directories",
24922490
"getrandom",
24932491
"jemalloc-sys",
2494-
"lazy_static",
24952492
"libc",
24962493
"libffi",
24972494
"libloading",
@@ -4791,12 +4788,10 @@ dependencies = [
47914788
"arrayvec",
47924789
"askama",
47934790
"base64",
4794-
"byteorder",
47954791
"expect-test",
47964792
"indexmap",
47974793
"itertools 0.12.1",
47984794
"minifier",
4799-
"once_cell",
48004795
"regex",
48014796
"rustdoc-json-types",
48024797
"serde",
@@ -5351,7 +5346,6 @@ version = "0.1.0"
53515346
dependencies = [
53525347
"build_helper",
53535348
"glob",
5354-
"once_cell",
53555349
]
53565350

53575351
[[package]]
@@ -5596,7 +5590,6 @@ version = "0.1.0"
55965590
dependencies = [
55975591
"cargo_metadata 0.15.4",
55985592
"ignore",
5599-
"lazy_static",
56005593
"miropt-test-tools",
56015594
"regex",
56025595
"rustc-hash",

src/librustdoc/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ path = "lib.rs"
1010
arrayvec = { version = "0.7", default-features = false }
1111
askama = { version = "0.12", default-features = false, features = ["config"] }
1212
base64 = "0.21.7"
13-
byteorder = "1.5"
1413
itertools = "0.12"
1514
indexmap = "2"
1615
minifier = "0.3.0"
17-
once_cell = "1.10.0"
1816
regex = "1"
1917
rustdoc-json-types = { path = "../rustdoc-json-types" }
2018
serde_json = "1.0"

src/librustdoc/html/markdown.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ use rustc_resolve::rustdoc::may_be_doc_link;
3535
use rustc_span::edition::Edition;
3636
use rustc_span::{Span, Symbol};
3737

38-
use once_cell::sync::Lazy;
3938
use std::borrow::Cow;
4039
use std::collections::VecDeque;
4140
use std::fmt::Write;
4241
use std::iter::Peekable;
4342
use std::ops::{ControlFlow, Range};
4443
use std::str::{self, CharIndices};
44+
use std::sync::OnceLock;
4545

4646
use crate::clean::RenderedLink;
4747
use crate::doctest;
@@ -1994,7 +1994,7 @@ pub struct IdMap {
19941994
}
19951995

19961996
// The map is pre-initialized and cloned each time to avoid reinitializing it repeatedly.
1997-
static DEFAULT_ID_MAP: Lazy<FxHashMap<Cow<'static, str>, usize>> = Lazy::new(|| init_id_map());
1997+
static DEFAULT_ID_MAP: OnceLock<FxHashMap<Cow<'static, str>, usize>> = OnceLock::new();
19981998

19991999
fn init_id_map() -> FxHashMap<Cow<'static, str>, usize> {
20002000
let mut map = FxHashMap::default();
@@ -2051,7 +2051,7 @@ fn init_id_map() -> FxHashMap<Cow<'static, str>, usize> {
20512051

20522052
impl IdMap {
20532053
pub fn new() -> Self {
2054-
IdMap { map: DEFAULT_ID_MAP.clone() }
2054+
IdMap { map: DEFAULT_ID_MAP.get_or_init(init_id_map).clone() }
20552055
}
20562056

20572057
pub(crate) fn derive<S: AsRef<str> + ToString>(&mut self, candidate: S) -> String {

src/librustdoc/html/render/search_index/encode.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -166,43 +166,42 @@ pub(crate) fn write_bitmap_to_bytes(
166166
containers.push(container);
167167
}
168168
// https://github.com/RoaringBitmap/RoaringFormatSpec
169-
use byteorder::{WriteBytesExt, LE};
170169
const SERIAL_COOKIE_NO_RUNCONTAINER: u32 = 12346;
171170
const SERIAL_COOKIE: u32 = 12347;
172171
const NO_OFFSET_THRESHOLD: u32 = 4;
173172
let size: u32 = containers.len().try_into().unwrap();
174173
let start_offset = if has_run {
175-
out.write_u32::<LE>(SERIAL_COOKIE | ((size - 1) << 16))?;
174+
out.write_all(&u32::to_le_bytes(SERIAL_COOKIE | ((size - 1) << 16)))?;
176175
for set in containers.chunks(8) {
177176
let mut b = 0;
178177
for (i, container) in set.iter().enumerate() {
179178
if matches!(container, &Container::Run(..)) {
180179
b |= 1 << i;
181180
}
182181
}
183-
out.write_u8(b)?;
182+
out.write_all(&[b])?;
184183
}
185184
if size < NO_OFFSET_THRESHOLD {
186185
4 + 4 * size + ((size + 7) / 8)
187186
} else {
188187
4 + 8 * size + ((size + 7) / 8)
189188
}
190189
} else {
191-
out.write_u32::<LE>(SERIAL_COOKIE_NO_RUNCONTAINER)?;
192-
out.write_u32::<LE>(containers.len().try_into().unwrap())?;
190+
out.write_all(&u32::to_le_bytes(SERIAL_COOKIE_NO_RUNCONTAINER))?;
191+
out.write_all(&u32::to_le_bytes(containers.len().try_into().unwrap()))?;
193192
4 + 4 + 4 * size + 4 * size
194193
};
195194
for (&key, container) in keys.iter().zip(&containers) {
196195
// descriptive header
197196
let key: u32 = key.into();
198197
let count: u32 = container.popcount() - 1;
199-
out.write_u32::<LE>((count << 16) | key)?;
198+
out.write_all(&u32::to_le_bytes((count << 16) | key))?;
200199
}
201200
if !has_run || size >= NO_OFFSET_THRESHOLD {
202201
// offset header
203202
let mut starting_offset = start_offset;
204203
for container in &containers {
205-
out.write_u32::<LE>(starting_offset)?;
204+
out.write_all(&u32::to_le_bytes(starting_offset))?;
206205
starting_offset += match container {
207206
Container::Bits(_) => 8192u32,
208207
Container::Array(array) => u32::try_from(array.len()).unwrap() * 2,
@@ -214,19 +213,19 @@ pub(crate) fn write_bitmap_to_bytes(
214213
match container {
215214
Container::Bits(bits) => {
216215
for chunk in bits.iter() {
217-
out.write_u64::<LE>(*chunk)?;
216+
out.write_all(&u64::to_le_bytes(*chunk))?;
218217
}
219218
}
220219
Container::Array(array) => {
221220
for value in array.iter() {
222-
out.write_u16::<LE>(*value)?;
221+
out.write_all(&u16::to_le_bytes(*value))?;
223222
}
224223
}
225224
Container::Run(runs) => {
226-
out.write_u16::<LE>((runs.len()).try_into().unwrap())?;
225+
out.write_all(&u16::to_le_bytes(runs.len().try_into().unwrap()))?;
227226
for (start, lenm1) in runs.iter().copied() {
228-
out.write_u16::<LE>(start)?;
229-
out.write_u16::<LE>(lenm1)?;
227+
out.write_all(&u16::to_le_bytes(start))?;
228+
out.write_all(&u16::to_le_bytes(lenm1))?;
230229
}
231230
}
232231
}

src/tools/jsondocck/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ regex = "1.4"
1010
shlex = "1.0"
1111
serde_json = "1.0"
1212
fs-err = "2.5.0"
13-
once_cell = "1.0"

src/tools/jsondocck/src/main.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use jsonpath_lib::select;
2-
use once_cell::sync::Lazy;
32
use regex::{Regex, RegexBuilder};
43
use serde_json::Value;
54
use std::borrow::Cow;
5+
use std::sync::OnceLock;
66
use std::{env, fmt, fs};
77

88
mod cache;
@@ -95,7 +95,8 @@ impl fmt::Display for CommandKind {
9595
}
9696
}
9797

98-
static LINE_PATTERN: Lazy<Regex> = Lazy::new(|| {
98+
static LINE_PATTERN: OnceLock<Regex> = OnceLock::new();
99+
fn line_pattern() -> Regex {
99100
RegexBuilder::new(
100101
r#"
101102
\s(?P<invalid>!?)@(?P<negated>!?)
@@ -107,7 +108,7 @@ static LINE_PATTERN: Lazy<Regex> = Lazy::new(|| {
107108
.unicode(true)
108109
.build()
109110
.unwrap()
110-
});
111+
}
111112

112113
fn print_err(msg: &str, lineno: usize) {
113114
eprintln!("Invalid command: {} on line {}", msg, lineno)
@@ -123,7 +124,7 @@ fn get_commands(template: &str) -> Result<Vec<Command>, ()> {
123124
for (lineno, line) in file.split('\n').enumerate() {
124125
let lineno = lineno + 1;
125126

126-
let cap = match LINE_PATTERN.captures(line) {
127+
let cap = match LINE_PATTERN.get_or_init(line_pattern).captures(line) {
127128
Some(c) => c,
128129
None => continue,
129130
};

src/tools/linkchecker/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ path = "main.rs"
99

1010
[dependencies]
1111
regex = "1"
12-
once_cell = "1"
1312
html5ever = "0.26.0"

src/tools/linkchecker/main.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ use html5ever::tendril::ByteTendril;
1818
use html5ever::tokenizer::{
1919
BufferQueue, TagToken, Token, TokenSink, TokenSinkResult, Tokenizer, TokenizerOpts,
2020
};
21-
use once_cell::sync::Lazy;
22-
use regex::Regex;
2321
use std::cell::RefCell;
2422
use std::collections::{HashMap, HashSet};
2523
use std::env;
@@ -69,8 +67,12 @@ const INTRA_DOC_LINK_EXCEPTIONS: &[(&str, &[&str])] = &[
6967

7068
];
7169

72-
static BROKEN_INTRA_DOC_LINK: Lazy<Regex> =
73-
Lazy::new(|| Regex::new(r#"\[<code>(.*)</code>\]"#).unwrap());
70+
macro_rules! static_regex {
71+
($re:literal) => {{
72+
static RE: ::std::sync::OnceLock<::regex::Regex> = ::std::sync::OnceLock::new();
73+
RE.get_or_init(|| ::regex::Regex::new($re).unwrap())
74+
}};
75+
}
7476

7577
macro_rules! t {
7678
($e:expr) => {
@@ -373,7 +375,7 @@ impl Checker {
373375
// Search for intra-doc links that rustdoc didn't warn about
374376
// NOTE: only looks at one line at a time; in practice this should find most links
375377
for (i, line) in source.lines().enumerate() {
376-
for broken_link in BROKEN_INTRA_DOC_LINK.captures_iter(line) {
378+
for broken_link in static_regex!(r#"\[<code>(.*)</code>\]"#).captures_iter(line) {
377379
if is_intra_doc_exception(file, &broken_link[1]) {
378380
report.intra_doc_exceptions += 1;
379381
} else {

src/tools/miri/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ colored = "2"
4646
ui_test = "0.21.1"
4747
rustc_version = "0.4"
4848
regex = "1.5.5"
49-
lazy_static = "1.4.0"
5049
tempfile = "3"
5150

5251
[package.metadata.rust-analyzer]

src/tools/miri/tests/ui.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::ffi::OsString;
22
use std::num::NonZeroUsize;
33
use std::path::{Path, PathBuf};
4+
use std::sync::OnceLock;
45
use std::{env, process::Command};
56

67
use colored::*;
@@ -67,8 +68,8 @@ fn miri_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) ->
6768

6869
let mut config = Config {
6970
target: Some(target.to_owned()),
70-
stderr_filters: STDERR.clone(),
71-
stdout_filters: STDOUT.clone(),
71+
stderr_filters: stderr_filters().into(),
72+
stdout_filters: stdout_filters().into(),
7273
mode,
7374
program,
7475
out_dir: PathBuf::from(std::env::var_os("CARGO_TARGET_DIR").unwrap()).join("ui"),
@@ -174,15 +175,18 @@ fn run_tests(
174175
}
175176

176177
macro_rules! regexes {
177-
($name:ident: $($regex:expr => $replacement:expr,)*) => {lazy_static::lazy_static! {
178-
static ref $name: Vec<(Match, &'static [u8])> = vec![
179-
$((Regex::new($regex).unwrap().into(), $replacement.as_bytes()),)*
180-
];
181-
}};
178+
($name:ident: $($regex:expr => $replacement:expr,)*) => {
179+
fn $name() -> &'static [(Match, &'static [u8])] {
180+
static S: OnceLock<Vec<(Match, &'static [u8])>> = OnceLock::new();
181+
S.get_or_init(|| vec![
182+
$((Regex::new($regex).unwrap().into(), $replacement.as_bytes()),)*
183+
])
184+
}
185+
};
182186
}
183187

184188
regexes! {
185-
STDOUT:
189+
stdout_filters:
186190
// Windows file paths
187191
r"\\" => "/",
188192
// erase borrow tags
@@ -191,7 +195,7 @@ regexes! {
191195
}
192196

193197
regexes! {
194-
STDERR:
198+
stderr_filters:
195199
// erase line and column info
196200
r"\.rs:[0-9]+:[0-9]+(: [0-9]+:[0-9]+)?" => ".rs:LL:CC",
197201
// erase alloc ids

src/tools/suggest-tests/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ edition = "2021"
66
[dependencies]
77
glob = "0.3.0"
88
build_helper = { version = "0.1.0", path = "../build_helper" }
9-
once_cell = "1.17.1"

src/tools/suggest-tests/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55

66
use dynamic_suggestions::DYNAMIC_SUGGESTIONS;
77
use glob::Pattern;
8-
use static_suggestions::STATIC_SUGGESTIONS;
8+
use static_suggestions::static_suggestions;
99

1010
mod dynamic_suggestions;
1111
mod static_suggestions;
@@ -33,7 +33,7 @@ pub fn get_suggestions<T: AsRef<str>>(modified_files: &[T]) -> Vec<Suggestion> {
3333
let mut suggestions = Vec::new();
3434

3535
// static suggestions
36-
for (globs, sugs) in STATIC_SUGGESTIONS.iter() {
36+
for (globs, sugs) in static_suggestions().iter() {
3737
let globs = globs
3838
.iter()
3939
.map(|glob| Pattern::new(glob).expect("Found invalid glob pattern!"))

src/tools/suggest-tests/src/static_suggestions.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
use crate::{sug, Suggestion};
2+
use std::sync::OnceLock;
23

34
// FIXME: perhaps this could use `std::lazy` when it is stablizied
45
macro_rules! static_suggestions {
56
($( [ $( $glob:expr ),* $(,)? ] => [ $( $suggestion:expr ),* $(,)? ] ),* $(,)? ) => {
6-
pub(crate) const STATIC_SUGGESTIONS: ::once_cell::unsync::Lazy<Vec<(Vec<&'static str>, Vec<Suggestion>)>>
7-
= ::once_cell::unsync::Lazy::new(|| vec![ $( (vec![ $($glob),* ], vec![ $($suggestion),* ]) ),*]);
7+
pub(crate) fn static_suggestions() -> &'static [(Vec<&'static str>, Vec<Suggestion>)]
8+
{
9+
static S: OnceLock<Vec<(Vec<&'static str>, Vec<Suggestion>)>> = OnceLock::new();
10+
S.get_or_init(|| vec![ $( (vec![ $($glob),* ], vec![ $($suggestion),* ]) ),*])
11+
}
812
}
913
}
1014

src/tools/tidy/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ autobins = false
88
cargo_metadata = "0.15"
99
regex = "1"
1010
miropt-test-tools = { path = "../miropt-test-tools" }
11-
lazy_static = "1"
1211
walkdir = "2"
1312
ignore = "0.4.18"
1413
semver = "1.0"

0 commit comments

Comments
 (0)