Skip to content

Commit 58bbd2e

Browse files
committed
Auto merge of #12217 - weihanglo:1.70-cleanup, r=epage
refactor: housekeeping for 1.70.0
2 parents 81999d4 + 423eb4e commit 58bbd2e

File tree

13 files changed

+57
-57
lines changed

13 files changed

+57
-57
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ defaults:
1212
permissions:
1313
contents: read
1414

15-
env:
16-
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
17-
1815
jobs:
1916
# Check Code style quickly by running `rustfmt` over all code
2017
rustfmt:

Cargo.lock

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ humantime = "2.0.0"
4545
ignore = "0.4.7"
4646
im-rc = "15.0.0"
4747
indexmap = "1"
48-
is-terminal = "0.4.4"
4948
itertools = "0.10.0"
5049
jobserver = "0.1.26"
5150
lazy_static = "1.3.0"
@@ -136,10 +135,8 @@ humantime.workspace = true
136135
ignore.workspace = true
137136
im-rc.workspace = true
138137
indexmap.workspace = true
139-
is-terminal.workspace = true
140138
itertools.workspace = true
141139
jobserver.workspace = true
142-
lazy_static.workspace = true
143140
lazycell.workspace = true
144141
libc.workspace = true
145142
libgit2-sys.workspace = true

crates/cargo-test-support/src/paths.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
use filetime::{self, FileTime};
2-
use lazy_static::lazy_static;
2+
33
use std::cell::RefCell;
4-
use std::collections::HashMap;
54
use std::env;
65
use std::fs;
76
use std::io::{self, ErrorKind};
87
use std::path::{Path, PathBuf};
98
use std::process::Command;
109
use std::sync::atomic::{AtomicUsize, Ordering};
1110
use std::sync::Mutex;
11+
use std::sync::OnceLock;
1212

1313
static CARGO_INTEGRATION_TEST_DIR: &str = "cit";
1414

15-
lazy_static! {
16-
// TODO: Use `SyncOnceCell` when stable
17-
static ref GLOBAL_ROOT: Mutex<Option<PathBuf>> = Mutex::new(None);
18-
19-
static ref TEST_ROOTS: Mutex<HashMap<String, PathBuf>> = Default::default();
20-
}
15+
static GLOBAL_ROOT: OnceLock<Mutex<Option<PathBuf>>> = OnceLock::new();
2116

2217
/// This is used when running cargo is pre-CARGO_TARGET_TMPDIR
2318
/// TODO: Remove when CARGO_TARGET_TMPDIR grows old enough.
@@ -31,7 +26,10 @@ fn global_root_legacy() -> PathBuf {
3126
}
3227

3328
fn set_global_root(tmp_dir: Option<&'static str>) {
34-
let mut lock = GLOBAL_ROOT.lock().unwrap();
29+
let mut lock = GLOBAL_ROOT
30+
.get_or_init(|| Default::default())
31+
.lock()
32+
.unwrap();
3533
if lock.is_none() {
3634
let mut root = match tmp_dir {
3735
Some(tmp_dir) => PathBuf::from(tmp_dir),
@@ -44,7 +42,10 @@ fn set_global_root(tmp_dir: Option<&'static str>) {
4442
}
4543

4644
pub fn global_root() -> PathBuf {
47-
let lock = GLOBAL_ROOT.lock().unwrap();
45+
let lock = GLOBAL_ROOT
46+
.get_or_init(|| Default::default())
47+
.lock()
48+
.unwrap();
4849
match lock.as_ref() {
4950
Some(p) => p.clone(),
5051
None => unreachable!("GLOBAL_ROOT not set yet"),

crates/cargo-test-support/src/tools.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
//! Common executables that can be reused by various tests.
22
33
use crate::{basic_manifest, paths, project, Project};
4-
use lazy_static::lazy_static;
54
use std::path::{Path, PathBuf};
65
use std::sync::Mutex;
6+
use std::sync::OnceLock;
77

8-
lazy_static! {
9-
static ref ECHO_WRAPPER: Mutex<Option<PathBuf>> = Mutex::new(None);
10-
static ref ECHO: Mutex<Option<PathBuf>> = Mutex::new(None);
11-
}
8+
static ECHO_WRAPPER: OnceLock<Mutex<Option<PathBuf>>> = OnceLock::new();
9+
static ECHO: OnceLock<Mutex<Option<PathBuf>>> = OnceLock::new();
1210

1311
/// Returns the path to an executable that works as a wrapper around rustc.
1412
///
1513
/// The wrapper will echo the command line it was called with to stderr.
1614
pub fn echo_wrapper() -> PathBuf {
17-
let mut lock = ECHO_WRAPPER.lock().unwrap();
15+
let mut lock = ECHO_WRAPPER
16+
.get_or_init(|| Default::default())
17+
.lock()
18+
.unwrap();
1819
if let Some(path) = &*lock {
1920
return path.clone();
2021
}
@@ -53,7 +54,7 @@ pub fn echo_wrapper() -> PathBuf {
5354
///
5455
/// Do not expect this to be anything fancy.
5556
pub fn echo() -> PathBuf {
56-
let mut lock = ECHO.lock().unwrap();
57+
let mut lock = ECHO.get_or_init(|| Default::default()).lock().unwrap();
5758
if let Some(path) = &*lock {
5859
return path.clone();
5960
}

crates/resolver-tests/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ publish = false
77
[dependencies]
88
cargo.workspace = true
99
cargo-util.workspace = true
10-
is-terminal.workspace = true
1110
lazy_static.workspace = true
1211
proptest.workspace = true
1312
varisat.workspace = true

crates/resolver-tests/tests/resolve.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::io::IsTerminal;
2+
13
use cargo::core::dependency::DepKind;
24
use cargo::core::Dependency;
35
use cargo::util::Config;
@@ -21,7 +23,7 @@ use proptest::prelude::*;
2123
proptest! {
2224
#![proptest_config(ProptestConfig {
2325
max_shrink_iters:
24-
if is_ci() || !is_terminal::IsTerminal::is_terminal(&std::io::stderr()){
26+
if is_ci() || !std::io::stderr().is_terminal() {
2527
// This attempts to make sure that CI will fail fast,
2628
0
2729
} else {

src/bin/cargo/cli.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ use super::list_commands;
1414
use crate::command_prelude::*;
1515
use cargo::core::features::HIDDEN;
1616

17-
lazy_static::lazy_static! {
18-
// Maps from commonly known external commands (not builtin to cargo) to their
19-
// description, for the help page. Reserved for external subcommands that are
20-
// core within the rust ecosystem (esp ones that might become internal in the future).
21-
static ref KNOWN_EXTERNAL_COMMAND_DESCRIPTIONS: HashMap<&'static str, &'static str> = HashMap::from([
22-
("clippy", "Checks a package to catch common mistakes and improve your Rust code."),
23-
("fmt", "Formats all bin and lib files of the current crate using rustfmt."),
24-
]);
25-
}
26-
2717
pub fn main(config: &mut LazyConfig) -> CliResult {
2818
let args = cli().try_get_matches()?;
2919

@@ -128,15 +118,28 @@ Run with 'cargo -Z [FLAG] [COMMAND]'",
128118
}
129119

130120
if expanded_args.flag("list") {
121+
// Maps from commonly known external commands (not builtin to cargo)
122+
// to their description, for the help page. Reserved for external
123+
// subcommands that are core within the rust ecosystem (esp ones that
124+
// might become internal in the future).
125+
let known_external_command_descriptions = HashMap::from([
126+
(
127+
"clippy",
128+
"Checks a package to catch common mistakes and improve your Rust code.",
129+
),
130+
(
131+
"fmt",
132+
"Formats all bin and lib files of the current crate using rustfmt.",
133+
),
134+
]);
131135
drop_println!(config, "Installed Commands:");
132136
for (name, command) in list_commands(config) {
133-
let known_external_desc = KNOWN_EXTERNAL_COMMAND_DESCRIPTIONS.get(name.as_str());
137+
let known_external_desc = known_external_command_descriptions.get(name.as_str());
134138
match command {
135139
CommandInfo::BuiltIn { about } => {
136140
assert!(
137141
known_external_desc.is_none(),
138-
"KNOWN_EXTERNAL_COMMANDS shouldn't contain builtin \"{}\"",
139-
name
142+
"known_external_commands shouldn't contain builtin `{name}`",
140143
);
141144
let summary = about.unwrap_or_default();
142145
let summary = summary.lines().next().unwrap_or(&summary); // display only the first line

src/cargo/core/package_id.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::hash::Hash;
55
use std::path::Path;
66
use std::ptr;
77
use std::sync::Mutex;
8+
use std::sync::OnceLock;
89

910
use serde::de;
1011
use serde::ser;
@@ -13,10 +14,7 @@ use crate::core::source::SourceId;
1314
use crate::util::interning::InternedString;
1415
use crate::util::{CargoResult, ToSemver};
1516

16-
lazy_static::lazy_static! {
17-
static ref PACKAGE_ID_CACHE: Mutex<HashSet<&'static PackageIdInner>> =
18-
Mutex::new(HashSet::new());
19-
}
17+
static PACKAGE_ID_CACHE: OnceLock<Mutex<HashSet<&'static PackageIdInner>>> = OnceLock::new();
2018

2119
/// Identifier for a specific version of a package in a specific source.
2220
#[derive(Clone, Copy, Eq, PartialOrd, Ord)]
@@ -147,7 +145,10 @@ impl PackageId {
147145
version,
148146
source_id,
149147
};
150-
let mut cache = PACKAGE_ID_CACHE.lock().unwrap();
148+
let mut cache = PACKAGE_ID_CACHE
149+
.get_or_init(|| Default::default())
150+
.lock()
151+
.unwrap();
151152
let inner = cache.get(&inner).cloned().unwrap_or_else(|| {
152153
let inner = Box::leak(Box::new(inner));
153154
cache.insert(inner);

src/cargo/core/shell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt;
22
use std::io::prelude::*;
3+
use std::io::IsTerminal;
34

4-
use is_terminal::IsTerminal;
55
use termcolor::Color::{Cyan, Green, Red, Yellow};
66
use termcolor::{self, Color, ColorSpec, StandardStream, WriteColor};
77

src/cargo/core/source/source_id.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ use std::hash::{self, Hash};
1313
use std::path::{Path, PathBuf};
1414
use std::ptr;
1515
use std::sync::Mutex;
16+
use std::sync::OnceLock;
1617
use url::Url;
1718

18-
lazy_static::lazy_static! {
19-
static ref SOURCE_ID_CACHE: Mutex<HashSet<&'static SourceIdInner>> = Default::default();
20-
}
19+
static SOURCE_ID_CACHE: OnceLock<Mutex<HashSet<&'static SourceIdInner>>> = OnceLock::new();
2120

2221
/// Unique identifier for a source of packages.
2322
///
@@ -118,7 +117,10 @@ impl SourceId {
118117

119118
/// Interns the value and returns the wrapped type.
120119
fn wrap(inner: SourceIdInner) -> SourceId {
121-
let mut cache = SOURCE_ID_CACHE.lock().unwrap();
120+
let mut cache = SOURCE_ID_CACHE
121+
.get_or_init(|| Default::default())
122+
.lock()
123+
.unwrap();
122124
let inner = cache.get(&inner).cloned().unwrap_or_else(|| {
123125
let inner = Box::leak(Box::new(inner));
124126
cache.insert(inner);

src/cargo/ops/cargo_test.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,6 @@ fn run_doc_tests(
217217

218218
if doctest_in_workspace {
219219
add_path_args(ws, unit, &mut p);
220-
// FIXME(swatinem): remove the `unstable-options` once rustdoc stabilizes the `test-run-directory` option
221-
p.arg("-Z").arg("unstable-options");
222220
p.arg("--test-run-directory")
223221
.arg(unit.pkg.root().to_path_buf());
224222
} else {

src/cargo/util/interning.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ use std::path::Path;
1010
use std::ptr;
1111
use std::str;
1212
use std::sync::Mutex;
13+
use std::sync::OnceLock;
1314

1415
fn leak(s: String) -> &'static str {
1516
Box::leak(s.into_boxed_str())
1617
}
1718

18-
lazy_static::lazy_static! {
19-
static ref STRING_CACHE: Mutex<HashSet<&'static str>> = Mutex::new(HashSet::new());
20-
}
19+
static STRING_CACHE: OnceLock<Mutex<HashSet<&'static str>>> = OnceLock::new();
2120

2221
#[derive(Clone, Copy)]
2322
pub struct InternedString {
@@ -64,7 +63,10 @@ impl Eq for InternedString {}
6463

6564
impl InternedString {
6665
pub fn new(str: &str) -> InternedString {
67-
let mut cache = STRING_CACHE.lock().unwrap();
66+
let mut cache = STRING_CACHE
67+
.get_or_init(|| Default::default())
68+
.lock()
69+
.unwrap();
6870
let s = cache.get(str).cloned().unwrap_or_else(|| {
6971
let s = leak(str.to_string());
7072
cache.insert(s);

0 commit comments

Comments
 (0)