Skip to content

Commit f8bfbe1

Browse files
sunshowershawkw
authored andcommitted
[meta] switch to once_cell impls in std (#7580)
`once_cell` is now part of std, so switch over to it almost everywhere, and add lints for it. This is purely mechanical -- there are no semantic changes compared to `once_cell`. There's one place that still needs `once_cell`'s `try_`, so keep that around. See rust-lang/rust#109737.
1 parent 3599fa2 commit f8bfbe1

File tree

44 files changed

+710
-673
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+710
-673
lines changed

Cargo.lock

-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clippy.toml

+11
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,15 @@ disallowed-methods = [
1616
# Instead, the "transaction_retry_wrapper" should be preferred, as it
1717
# automatically retries transactions experiencing contention.
1818
{ path = "async_bb8_diesel::AsyncConnection::transaction_async", reason = "Prefer to use transaction_retry_wrapper, if possible. For tests and nested transactions, use transaction_non_retry_wrapper to at least get dtrace probes" },
19+
20+
# We use disallowed-methods for these rather than disallowed-types, because
21+
# there's still one legitimate use for `once_cell`'s types:
22+
# `get_or_try_init`, which isn't stablet yet.
23+
# https://github.com/rust-lang/rust/issues/109737
24+
{ path = "once_cell::unsync::OnceCell::get_or_init", reason = "use `std::cell::OnceCell` instead, unless you need get_or_try_init in which case #[expect] this lint" },
25+
{ path = "once_cell::sync::OnceCell::get_or_init", reason = "use `std::sync::OnceLock` instead, unless you need get_or_try_init in which case #[expect] this lint" },
26+
]
27+
disallowed-types = [
28+
{ path = "once_cell::unsync::Lazy", reason = "use `std::cell::LazyCell` instead" },
29+
{ path = "once_cell::unsync::LazyCell", reason = "use `std::cell::LazyCell` instead" },
1930
]

cockroach-admin/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ http.workspace = true
2020
illumos-utils.workspace = true
2121
omicron-common.workspace = true
2222
omicron-uuid-kinds.workspace = true
23-
once_cell.workspace = true
2423
# See omicron-rpaths for more about the "pq-sys" dependency.
2524
pq-sys = "*"
2625
schemars.workspace = true

common/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ uuid.workspace = true
4949
parse-display.workspace = true
5050
progenitor-client.workspace = true
5151
omicron-workspace-hack.workspace = true
52-
once_cell.workspace = true
5352
regress.workspace = true
5453

5554
[dev-dependencies]

common/src/address.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
use crate::api::external::{self, Error};
1111
use crate::policy::INTERNAL_DNS_REDUNDANCY;
1212
use ipnetwork::Ipv6Network;
13-
use once_cell::sync::Lazy;
1413
use oxnet::{Ipv4Net, Ipv6Net};
1514
use schemars::JsonSchema;
1615
use serde::{Deserialize, Serialize};
17-
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV6};
16+
use std::{
17+
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV6},
18+
sync::LazyLock,
19+
};
1820

1921
pub const AZ_PREFIX: u8 = 48;
2022
pub const RACK_PREFIX: u8 = 56;
@@ -101,7 +103,7 @@ pub const NUM_SOURCE_NAT_PORTS: u16 = 1 << 14;
101103
// prefix range (`fd00::/48`). See `random_vpc_ipv6_prefix`.
102104
// Furthermore, all the below *_OPTE_IPV6_SUBNET constants are
103105
// /64's within this prefix.
104-
pub static SERVICE_VPC_IPV6_PREFIX: Lazy<Ipv6Net> = Lazy::new(|| {
106+
pub static SERVICE_VPC_IPV6_PREFIX: LazyLock<Ipv6Net> = LazyLock::new(|| {
105107
Ipv6Net::new(
106108
Ipv6Addr::new(0xfd77, 0xe9d2, 0x9cd9, 0, 0, 0, 0, 0),
107109
VPC_IPV6_PREFIX_LENGTH,
@@ -110,11 +112,11 @@ pub static SERVICE_VPC_IPV6_PREFIX: Lazy<Ipv6Net> = Lazy::new(|| {
110112
});
111113

112114
/// The IPv4 subnet for External DNS OPTE ports.
113-
pub static DNS_OPTE_IPV4_SUBNET: Lazy<Ipv4Net> =
114-
Lazy::new(|| Ipv4Net::new(Ipv4Addr::new(172, 30, 1, 0), 24).unwrap());
115+
pub static DNS_OPTE_IPV4_SUBNET: LazyLock<Ipv4Net> =
116+
LazyLock::new(|| Ipv4Net::new(Ipv4Addr::new(172, 30, 1, 0), 24).unwrap());
115117

116118
/// The IPv6 subnet for External DNS OPTE ports.
117-
pub static DNS_OPTE_IPV6_SUBNET: Lazy<Ipv6Net> = Lazy::new(|| {
119+
pub static DNS_OPTE_IPV6_SUBNET: LazyLock<Ipv6Net> = LazyLock::new(|| {
118120
Ipv6Net::new(
119121
Ipv6Addr::new(0xfd77, 0xe9d2, 0x9cd9, 1, 0, 0, 0, 0),
120122
VPC_SUBNET_IPV6_PREFIX_LENGTH,
@@ -123,11 +125,11 @@ pub static DNS_OPTE_IPV6_SUBNET: Lazy<Ipv6Net> = Lazy::new(|| {
123125
});
124126

125127
/// The IPv4 subnet for Nexus OPTE ports.
126-
pub static NEXUS_OPTE_IPV4_SUBNET: Lazy<Ipv4Net> =
127-
Lazy::new(|| Ipv4Net::new(Ipv4Addr::new(172, 30, 2, 0), 24).unwrap());
128+
pub static NEXUS_OPTE_IPV4_SUBNET: LazyLock<Ipv4Net> =
129+
LazyLock::new(|| Ipv4Net::new(Ipv4Addr::new(172, 30, 2, 0), 24).unwrap());
128130

129131
/// The IPv6 subnet for Nexus OPTE ports.
130-
pub static NEXUS_OPTE_IPV6_SUBNET: Lazy<Ipv6Net> = Lazy::new(|| {
132+
pub static NEXUS_OPTE_IPV6_SUBNET: LazyLock<Ipv6Net> = LazyLock::new(|| {
131133
Ipv6Net::new(
132134
Ipv6Addr::new(0xfd77, 0xe9d2, 0x9cd9, 2, 0, 0, 0, 0),
133135
VPC_SUBNET_IPV6_PREFIX_LENGTH,
@@ -136,11 +138,11 @@ pub static NEXUS_OPTE_IPV6_SUBNET: Lazy<Ipv6Net> = Lazy::new(|| {
136138
});
137139

138140
/// The IPv4 subnet for Boundary NTP OPTE ports.
139-
pub static NTP_OPTE_IPV4_SUBNET: Lazy<Ipv4Net> =
140-
Lazy::new(|| Ipv4Net::new(Ipv4Addr::new(172, 30, 3, 0), 24).unwrap());
141+
pub static NTP_OPTE_IPV4_SUBNET: LazyLock<Ipv4Net> =
142+
LazyLock::new(|| Ipv4Net::new(Ipv4Addr::new(172, 30, 3, 0), 24).unwrap());
141143

142144
/// The IPv6 subnet for Boundary NTP OPTE ports.
143-
pub static NTP_OPTE_IPV6_SUBNET: Lazy<Ipv6Net> = Lazy::new(|| {
145+
pub static NTP_OPTE_IPV6_SUBNET: LazyLock<Ipv6Net> = LazyLock::new(|| {
144146
Ipv6Net::new(
145147
Ipv6Addr::new(0xfd77, 0xe9d2, 0x9cd9, 3, 0, 0, 0, 0),
146148
VPC_SUBNET_IPV6_PREFIX_LENGTH,

dev-tools/releng/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ omicron-common.workspace = true
1818
omicron-pins.workspace = true
1919
omicron-workspace-hack.workspace = true
2020
omicron-zone-package.workspace = true
21-
once_cell.workspace = true
2221
reqwest.workspace = true
2322
semver.workspace = true
2423
serde.workspace = true

dev-tools/releng/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod job;
88
mod tuf;
99

1010
use std::sync::Arc;
11+
use std::sync::LazyLock;
1112
use std::time::Duration;
1213
use std::time::Instant;
1314

@@ -20,7 +21,6 @@ use clap::Parser;
2021
use fs_err::tokio as fs;
2122
use omicron_zone_package::config::Config;
2223
use omicron_zone_package::config::PackageName;
23-
use once_cell::sync::Lazy;
2424
use semver::Version;
2525
use slog::debug;
2626
use slog::error;
@@ -88,7 +88,7 @@ const TUF_PACKAGES: [&PackageName; 11] = [
8888

8989
const HELIOS_REPO: &str = "https://pkg.oxide.computer/helios/2/dev/";
9090

91-
static WORKSPACE_DIR: Lazy<Utf8PathBuf> = Lazy::new(|| {
91+
static WORKSPACE_DIR: LazyLock<Utf8PathBuf> = LazyLock::new(|| {
9292
// $CARGO_MANIFEST_DIR is at `.../omicron/dev-tools/releng`
9393
let mut dir =
9494
Utf8PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").expect(

gateway/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ hyper.workspace = true
2525
illumos-utils.workspace = true
2626
ipcc.workspace = true
2727
omicron-common.workspace = true
28-
once_cell.workspace = true
2928
schemars.workspace = true
3029
serde.workspace = true
3130
signal-hook.workspace = true

gateway/src/management_switch.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use gateway_sp_comms::HostPhase2Provider;
2929
use gateway_sp_comms::SharedSocket;
3030
use gateway_sp_comms::SingleSp;
3131
use gateway_sp_comms::SpRetryConfig;
32-
use once_cell::sync::OnceCell;
3332
use serde::Deserialize;
3433
use serde::Serialize;
3534
use slog::o;
@@ -39,6 +38,7 @@ use std::collections::HashMap;
3938
use std::net::Ipv6Addr;
4039
use std::net::SocketAddrV6;
4140
use std::sync::Arc;
41+
use std::sync::OnceLock;
4242
use std::time::Duration;
4343
use tokio::net::UdpSocket;
4444
use tokio::task::JoinHandle;
@@ -162,7 +162,7 @@ pub struct ManagementSwitch {
162162
// When it's dropped, it cancels the background tokio task that loops on
163163
// that socket receiving incoming packets.
164164
_shared_socket: Option<SharedSocket>,
165-
location_map: Arc<OnceCell<Result<LocationMap, String>>>,
165+
location_map: Arc<OnceLock<Result<LocationMap, String>>>,
166166
discovery_task: JoinHandle<()>,
167167
log: Logger,
168168
}
@@ -290,7 +290,7 @@ impl ManagementSwitch {
290290
// completes (because we won't be able to map "the SP of sled 7" to a
291291
// correct switch port).
292292
let port_to_handle = Arc::new(port_to_handle);
293-
let location_map = Arc::new(OnceCell::new());
293+
let location_map = Arc::new(OnceLock::new());
294294
let discovery_task = {
295295
let log = log.clone();
296296
let port_to_handle = Arc::clone(&port_to_handle);

nexus/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ nexus-networking.workspace = true
5959
nexus-saga-recovery.workspace = true
6060
nexus-test-interface.workspace = true
6161
num-integer.workspace = true
62-
once_cell.workspace = true
6362
openssl.workspace = true
6463
oximeter-client.workspace = true
6564
oximeter-db = { workspace = true, default-features = false, features = [ "oxql" ] }

nexus/auth/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ hyper.workspace = true
2424
newtype_derive.workspace = true
2525
# See omicron-rpaths for more about the "pq-sys" dependency.
2626
pq-sys = "*"
27-
once_cell.workspace = true
2827
openssl.workspace = true
2928
oso.workspace = true
3029
samael.workspace = true

nexus/auth/src/authn/external/spoof.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
//! Custom, test-only authn scheme that trusts whatever the client says
66
7+
use std::sync::LazyLock;
8+
79
use super::super::Details;
810
use super::HttpAuthnScheme;
911
use super::Reason;
@@ -16,7 +18,6 @@ use anyhow::Context;
1618
use async_trait::async_trait;
1719
use headers::authorization::{Authorization, Bearer};
1820
use headers::HeaderMapExt;
19-
use once_cell::sync::Lazy;
2021
use slog::debug;
2122
use uuid::Uuid;
2223

@@ -56,20 +57,20 @@ const SPOOF_RESERVED_BAD_CREDS: &str = "this-fake-ID-it-is-truly-excellent";
5657
const SPOOF_PREFIX: &str = "oxide-spoof-";
5758

5859
/// Actor (id) used for the special "bad credentials" error
59-
static SPOOF_RESERVED_BAD_CREDS_ACTOR: Lazy<Actor> =
60-
Lazy::new(|| Actor::UserBuiltin {
60+
static SPOOF_RESERVED_BAD_CREDS_ACTOR: LazyLock<Actor> =
61+
LazyLock::new(|| Actor::UserBuiltin {
6162
user_builtin_id: "22222222-2222-2222-2222-222222222222"
6263
.parse()
6364
.unwrap(),
6465
});
6566

6667
/// Complete HTTP header value to trigger the "bad actor" error
67-
pub static SPOOF_HEADER_BAD_ACTOR: Lazy<Authorization<Bearer>> =
68-
Lazy::new(|| make_header_value_str(SPOOF_RESERVED_BAD_ACTOR).unwrap());
68+
pub static SPOOF_HEADER_BAD_ACTOR: LazyLock<Authorization<Bearer>> =
69+
LazyLock::new(|| make_header_value_str(SPOOF_RESERVED_BAD_ACTOR).unwrap());
6970

7071
/// Complete HTTP header value to trigger the "bad creds" error
71-
pub static SPOOF_HEADER_BAD_CREDS: Lazy<Authorization<Bearer>> =
72-
Lazy::new(|| make_header_value_str(SPOOF_RESERVED_BAD_CREDS).unwrap());
72+
pub static SPOOF_HEADER_BAD_CREDS: LazyLock<Authorization<Bearer>> =
73+
LazyLock::new(|| make_header_value_str(SPOOF_RESERVED_BAD_CREDS).unwrap());
7374

7475
/// Implements a (test-only) authentication scheme where the client simply
7576
/// provides the actor information in a custom bearer token and we always trust

nexus/auth/src/authz/api_resources.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
//!
2727
//! Most `authz` types are generated by the `authz_resource!` macro.
2828
29+
use std::sync::LazyLock;
30+
2931
use super::actor::AnyActor;
3032
use super::context::AuthorizedResource;
3133
use super::oso_generic::Init;
@@ -40,7 +42,6 @@ use futures::FutureExt;
4042
use nexus_db_fixed_data::FLEET_ID;
4143
use nexus_types::external_api::shared::{FleetRole, ProjectRole, SiloRole};
4244
use omicron_common::api::external::{Error, LookupType, ResourceType};
43-
use once_cell::sync::Lazy;
4445
use oso::PolarClass;
4546
use serde::{Deserialize, Serialize};
4647
use uuid::Uuid;
@@ -159,8 +160,8 @@ pub struct Fleet;
159160
/// Singleton representing the [`Fleet`] itself for authz purposes
160161
pub const FLEET: Fleet = Fleet;
161162

162-
pub static FLEET_LOOKUP: Lazy<LookupType> =
163-
Lazy::new(|| LookupType::ById(*FLEET_ID));
163+
pub static FLEET_LOOKUP: LazyLock<LookupType> =
164+
LazyLock::new(|| LookupType::ById(*FLEET_ID));
164165

165166
impl Eq for Fleet {}
166167
impl PartialEq for Fleet {

nexus/db-fixed-data/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ workspace = true
1212
omicron-rpaths.workspace = true
1313

1414
[dependencies]
15-
once_cell.workspace = true
1615
# See omicron-rpaths for more about the "pq-sys" dependency.
1716
pq-sys = "*"
1817
strum.workspace = true
@@ -22,4 +21,3 @@ nexus-db-model.workspace = true
2221
nexus-types.workspace = true
2322
omicron-common.workspace = true
2423
omicron-workspace-hack.workspace = true
25-

0 commit comments

Comments
 (0)