Skip to content

Commit f2cd59a

Browse files
authored
chore(deps): Drop use of once_cell::{sync,unsync}::OnceCell (vectordotdev#17621)
* chore(deps): Drop use of `once_cell::{sync,unsync}::OnceCell` This is now part of `std::cell` and `std::sync`. This bumps the MSRV to 1.70.0 which is when those features were stabilized. * Fix `const fn` lint * Another const lint * Fix more uses * Deny `once_cell::sync::OnceCell` with clippy
1 parent c07c99d commit f2cd59a

File tree

14 files changed

+36
-34
lines changed

14 files changed

+36
-34
lines changed

Cargo.lock

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

clippy.toml

+5
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ cognitive-complexity-threshold = 75
55
disallowed-methods = [
66
{ path = "std::io::Write::write", reason = "This doesn't handle short writes, use `write_all` instead." },
77
]
8+
9+
disallowed-types = [
10+
{ path = "once_cell::sync::OnceCell", reason = "Use `std::sync::OnceLock` instead." },
11+
{ path = "once_cell::unsync::OnceCell", reason = "Use `std::cell::OnceCell` instead." },
12+
]

lib/vector-config/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ indexmap = { version = "2.0", default-features = false, features = ["std"] }
1818
inventory = { version = "0.3" }
1919
no-proxy = { version = "0.3.4", default-features = false, features = ["serialize"] }
2020
num-traits = { version = "0.2.16", default-features = false }
21-
once_cell = { version = "1", default-features = false }
2221
serde = { version = "1.0", default-features = false }
2322
serde_json = { version = "1.0", default-features = false, features = ["std"] }
2423
serde_with = { version = "3.3.0", default-features = false, features = ["std"] }

lib/vector-config/src/schema/parser/query.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use std::{fs::File, io::BufReader, path::Path};
1+
use std::{fs::File, io::BufReader, path::Path, sync::OnceLock};
22

3-
use once_cell::sync::OnceCell;
43
use serde_json::Value;
54
use snafu::Snafu;
65
use vector_config_common::{
@@ -415,8 +414,8 @@ impl<'a> QueryableSchema for SimpleSchema<'a> {
415414
}
416415

417416
fn schema_to_simple_schema(schema: &Schema) -> SimpleSchema<'_> {
418-
static TRUE_SCHEMA_OBJECT: OnceCell<SchemaObject> = OnceCell::new();
419-
static FALSE_SCHEMA_OBJECT: OnceCell<SchemaObject> = OnceCell::new();
417+
static TRUE_SCHEMA_OBJECT: OnceLock<SchemaObject> = OnceLock::new();
418+
static FALSE_SCHEMA_OBJECT: OnceLock<SchemaObject> = OnceLock::new();
420419

421420
let schema_object = match schema {
422421
Schema::Bool(bool) => {

lib/vector-core/src/config/log_schema.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
use std::sync::OnceLock;
2+
13
use lookup::lookup_v2::OptionalTargetPath;
24
use lookup::{OwnedTargetPath, OwnedValuePath};
3-
use once_cell::sync::{Lazy, OnceCell};
5+
use once_cell::sync::Lazy;
46
use vector_config::configurable_component;
57

6-
static LOG_SCHEMA: OnceCell<LogSchema> = OnceCell::new();
8+
static LOG_SCHEMA: OnceLock<LogSchema> = OnceLock::new();
79
static LOG_SCHEMA_DEFAULT: Lazy<LogSchema> = Lazy::new(LogSchema::default);
810

911
const MESSAGE: &str = "message";

lib/vector-core/src/config/telemetry.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
use once_cell::sync::{Lazy, OnceCell};
1+
use std::sync::OnceLock;
2+
3+
use once_cell::sync::Lazy;
24
use vector_common::request_metadata::GroupedCountByteSize;
35
use vector_config::configurable_component;
46

5-
static TELEMETRY: OnceCell<Telemetry> = OnceCell::new();
7+
static TELEMETRY: OnceLock<Telemetry> = OnceLock::new();
68
static TELEMETRY_DEFAULT: Lazy<Telemetry> = Lazy::new(Telemetry::default);
79

810
/// Loads the telemetry options from configurations and sets the global options.

lib/vector-core/src/metrics/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ mod recency;
44
mod recorder;
55
mod storage;
66

7-
use std::time::Duration;
7+
use std::{sync::OnceLock, time::Duration};
88

99
use chrono::Utc;
1010
use metrics::Key;
1111
use metrics_tracing_context::TracingContextLayer;
1212
use metrics_util::layers::Layer;
13-
use once_cell::sync::OnceCell;
1413
use snafu::Snafu;
1514

1615
pub use self::ddsketch::{AgentDDSketch, BinMap, Config};
@@ -29,7 +28,7 @@ pub enum Error {
2928
TimeoutMustBePositive { timeout: f64 },
3029
}
3130

32-
static CONTROLLER: OnceCell<Controller> = OnceCell::new();
31+
static CONTROLLER: OnceLock<Controller> = OnceLock::new();
3332

3433
// Cardinality counter parameters, expose the internal metrics registry
3534
// cardinality. Useful for the end users to help understand the characteristics

lib/vector-core/src/metrics/recorder.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use std::sync::{atomic::Ordering, Arc, RwLock};
2-
use std::time::Duration;
2+
use std::{cell::OnceCell, time::Duration};
33

44
use chrono::Utc;
55
use metrics::{Counter, Gauge, Histogram, Key, KeyName, Recorder, SharedString, Unit};
66
use metrics_util::{registry::Registry as MetricsRegistry, MetricKindMask};
7-
use once_cell::unsync::OnceCell;
87
use quanta::Clock;
98

109
use super::recency::{GenerationalStorage, Recency};

src/aws/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::error::Error;
66
use std::future::Future;
77
use std::pin::Pin;
88
use std::sync::atomic::{AtomicUsize, Ordering};
9-
use std::sync::Arc;
9+
use std::sync::{Arc, OnceLock};
1010
use std::task::{Context, Poll};
1111
use std::time::SystemTime;
1212

@@ -27,7 +27,6 @@ use aws_types::SdkConfig;
2727
use bytes::Bytes;
2828
use http::HeaderMap;
2929
use http_body::Body;
30-
use once_cell::sync::OnceCell;
3130
use pin_project::pin_project;
3231
use regex::RegexSet;
3332
pub use region::RegionOrEndpoint;
@@ -38,7 +37,7 @@ use crate::http::{build_proxy_connector, build_tls_connector};
3837
use crate::internal_events::AwsBytesSent;
3938
use crate::tls::{MaybeTlsSettings, TlsConfig};
4039

41-
static RETRIABLE_CODES: OnceCell<RegexSet> = OnceCell::new();
40+
static RETRIABLE_CODES: OnceLock<RegexSet> = OnceLock::new();
4241

4342
pub fn is_retriable_error<T>(error: &SdkError<T>) -> bool {
4443
match error {

src/proto/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ pub mod vector;
66

77
#[cfg(feature = "sinks-datadog_metrics")]
88
pub mod fds {
9-
use once_cell::sync::OnceCell;
9+
use std::sync::OnceLock;
10+
1011
use prost_reflect::DescriptorPool;
1112

1213
pub fn protobuf_descriptors() -> &'static DescriptorPool {
13-
static PROTOBUF_FDS: OnceCell<DescriptorPool> = OnceCell::new();
14+
static PROTOBUF_FDS: OnceLock<DescriptorPool> = OnceLock::new();
1415
PROTOBUF_FDS.get_or_init(|| {
1516
DescriptorPool::decode(include_bytes!(concat!(env!("OUT_DIR"), "/protobuf-fds.bin")).as_ref())
1617
.expect("should not fail to decode protobuf file descriptor set generated from build script")

src/sinks/datadog/metrics/encoder.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ use std::{
22
cmp,
33
io::{self, Write},
44
mem,
5-
sync::Arc,
5+
sync::{Arc, OnceLock},
66
};
77

88
use bytes::{BufMut, Bytes};
99
use chrono::{DateTime, Utc};
10-
use once_cell::sync::OnceCell;
1110
use prost::Message;
1211
use snafu::{ResultExt, Snafu};
1312
use vector_common::request_metadata::GroupedCountByteSize;
@@ -372,7 +371,7 @@ impl DatadogMetricsEncoder {
372371
}
373372

374373
fn get_sketch_payload_sketches_field_number() -> u32 {
375-
static SKETCH_PAYLOAD_SKETCHES_FIELD_NUM: OnceCell<u32> = OnceCell::new();
374+
static SKETCH_PAYLOAD_SKETCHES_FIELD_NUM: OnceLock<u32> = OnceLock::new();
376375
*SKETCH_PAYLOAD_SKETCHES_FIELD_NUM.get_or_init(|| {
377376
let descriptors = protobuf_descriptors();
378377
let descriptor = descriptors

src/sources/kafka.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{
22
collections::{BTreeMap, HashMap},
33
io::Cursor,
4-
sync::Arc,
4+
sync::{Arc, OnceLock},
55
time::Duration,
66
};
77

@@ -14,7 +14,6 @@ use codecs::{
1414
};
1515
use futures::{Stream, StreamExt};
1616
use lookup::{lookup_v2::OptionalValuePath, owned_value_path, path, OwnedValuePath};
17-
use once_cell::sync::OnceCell;
1817
use rdkafka::{
1918
consumer::{CommitMode, Consumer, ConsumerContext, Rebalance, StreamConsumer},
2019
message::{BorrowedMessage, Headers as _, Message},
@@ -727,7 +726,7 @@ fn create_consumer(config: &KafkaSourceConfig) -> crate::Result<StreamConsumer<C
727726
#[derive(Default)]
728727
struct CustomContext {
729728
stats: kafka::KafkaStatisticsContext,
730-
finalizer: OnceCell<Arc<OrderedFinalizer<FinalizerEntry>>>,
729+
finalizer: OnceLock<Arc<OrderedFinalizer<FinalizerEntry>>>,
731730
}
732731

733732
impl CustomContext {

src/trace.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ use std::{
55
str::FromStr,
66
sync::{
77
atomic::{AtomicBool, Ordering},
8-
Mutex, MutexGuard,
8+
Mutex, MutexGuard, OnceLock,
99
},
1010
};
1111

1212
use futures_util::{future::ready, Stream, StreamExt};
1313
use lookup::event_path;
1414
use metrics_tracing_context::MetricsLayer;
15-
use once_cell::sync::OnceCell;
1615
use tokio::sync::{
1716
broadcast::{self, Receiver, Sender},
1817
oneshot,
@@ -51,7 +50,7 @@ static SUBSCRIBERS: Mutex<Option<Vec<oneshot::Sender<Vec<LogEvent>>>>> =
5150

5251
/// SENDER holds the sender/receiver handle that will receive a copy of all the internal log events *after* the topology
5352
/// has been initialized.
54-
static SENDER: OnceCell<Sender<LogEvent>> = OnceCell::new();
53+
static SENDER: OnceLock<Sender<LogEvent>> = OnceLock::new();
5554

5655
fn metrics_layer_enabled() -> bool {
5756
!matches!(std::env::var("DISABLE_INTERNAL_METRICS_TRACING_INTEGRATION"), Ok(x) if x == "true")

vdev/src/app.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use std::ffi::{OsStr, OsString};
22
pub use std::process::Command;
33
use std::{
4-
borrow::Cow, env, io::Read, path::PathBuf, process::ExitStatus, process::Stdio, time::Duration,
4+
borrow::Cow, env, io::Read, path::PathBuf, process::ExitStatus, process::Stdio, sync::OnceLock,
5+
time::Duration,
56
};
67

78
use anyhow::{bail, Context as _, Result};
89
use indicatif::{ProgressBar, ProgressStyle};
910
use log::LevelFilter;
10-
use once_cell::sync::{Lazy, OnceCell};
11+
use once_cell::sync::Lazy;
1112

1213
use crate::{config::Config, git, platform, util};
1314

@@ -25,9 +26,9 @@ const DEFAULT_SHELL: &str = "/bin/sh";
2526
pub static SHELL: Lazy<OsString> =
2627
Lazy::new(|| (env::var_os("SHELL").unwrap_or_else(|| DEFAULT_SHELL.into())));
2728

28-
static VERBOSITY: OnceCell<LevelFilter> = OnceCell::new();
29-
static CONFIG: OnceCell<Config> = OnceCell::new();
30-
static PATH: OnceCell<String> = OnceCell::new();
29+
static VERBOSITY: OnceLock<LevelFilter> = OnceLock::new();
30+
static CONFIG: OnceLock<Config> = OnceLock::new();
31+
static PATH: OnceLock<String> = OnceLock::new();
3132

3233
pub fn verbosity() -> &'static LevelFilter {
3334
VERBOSITY.get().expect("verbosity is not initialized")

0 commit comments

Comments
 (0)