diff --git a/Cargo.lock b/Cargo.lock index 46bc610fe96..4bc192fb4c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -483,7 +483,6 @@ dependencies = [ "clap_builder 4.4.1", "clap_derive", "humantime", - "once_cell", "rustversion", "shlex", "snapbox", @@ -523,7 +522,6 @@ dependencies = [ "clap_lex 0.5.1", "color-print", "humantime", - "once_cell", "rustversion", "shlex", "snapbox", diff --git a/Cargo.toml b/Cargo.toml index 48490d95111..f4d4230be38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,7 +86,7 @@ suggestions = ["clap_builder/suggestions"] # Optional deprecated = ["clap_builder/deprecated", "clap_derive?/deprecated"] # Guided experience to prepare for next breaking release (at different stages of development, this may become default) -derive = ["dep:clap_derive", "dep:once_cell"] +derive = ["dep:clap_derive"] cargo = ["clap_builder/cargo"] # Disable if you're not using Cargo, enables Cargo-env-var-dependent macros wrap_help = ["clap_builder/wrap_help"] env = ["clap_builder/env"] # Use environment variables during arg parsing @@ -103,7 +103,6 @@ bench = false [dependencies] clap_builder = { path = "./clap_builder", version = "=4.4.1", default-features = false } clap_derive = { path = "./clap_derive", version = "=4.4.0", optional = true } -once_cell = { version = "1.12.0", optional = true } [dev-dependencies] trybuild = "1.0.82" diff --git a/clap_builder/Cargo.toml b/clap_builder/Cargo.toml index 0cbe5e3f244..a7573ec6302 100644 --- a/clap_builder/Cargo.toml +++ b/clap_builder/Cargo.toml @@ -44,7 +44,7 @@ suggestions = ["dep:strsim", "error-context"] # Optional deprecated = [] # Guided experience to prepare for next breaking release (at different stages of development, this may become default) -cargo = ["dep:once_cell"] # Disable if you're not using Cargo, enables Cargo-env-var-dependent macros +cargo = [] # Disable if you're not using Cargo, enables Cargo-env-var-dependent macros wrap_help = ["help", "dep:terminal_size"] env = [] # Use environment variables during arg parsing unicode = ["dep:unicode-width", "dep:unicase"] # Support for unicode characters in arguments and help messages @@ -66,7 +66,6 @@ anstyle = "1.0.0" terminal_size = { version = "0.2.1", optional = true } backtrace = { version = "0.3.67", optional = true } unicode-width = { version = "0.1.9", optional = true } -once_cell = { version = "1.12.0", optional = true } [dev-dependencies] trybuild = "1.0.82" diff --git a/clap_builder/src/lib.rs b/clap_builder/src/lib.rs index 97c32c141bd..7d49d41dfa3 100644 --- a/clap_builder/src/lib.rs +++ b/clap_builder/src/lib.rs @@ -48,13 +48,6 @@ pub type Error = crate::error::Error; pub use crate::derive::{Args, CommandFactory, FromArgMatches, Parser, Subcommand, ValueEnum}; -#[doc(hidden)] -pub mod __macro_refs { - #[cfg(feature = "cargo")] - #[doc(hidden)] - pub use once_cell; -} - #[macro_use] #[allow(missing_docs)] mod macros; diff --git a/clap_builder/src/macros.rs b/clap_builder/src/macros.rs index 945cdaaabaf..767ea94bc02 100644 --- a/clap_builder/src/macros.rs +++ b/clap_builder/src/macros.rs @@ -44,9 +44,9 @@ macro_rules! crate_authors { ($sep:expr) => {{ static authors: &str = env!("CARGO_PKG_AUTHORS"); if authors.contains(':') { - static CACHED: clap::__macro_refs::once_cell::sync::Lazy = - clap::__macro_refs::once_cell::sync::Lazy::new(|| authors.replace(':', $sep)); - let s: &'static str = &*CACHED; + static CACHED: std::sync::OnceLock = std::sync::OnceLock::new(); + let s = CACHED.get_or_init(|| authors.replace(':', $sep)); + let s: &'static str = &*s; s } else { authors diff --git a/clap_derive/src/item.rs b/clap_derive/src/item.rs index f3631fa7f09..114849f6950 100644 --- a/clap_derive/src/item.rs +++ b/clap_derive/src/item.rs @@ -575,20 +575,22 @@ impl Item { .any(|a| a.magic == Some(MagicAttrName::ValueEnum)) { quote_spanned!(attr.name.clone().span()=> { - static DEFAULT_VALUE: clap::__derive_refs::once_cell::sync::Lazy = clap::__derive_refs::once_cell::sync::Lazy::new(|| { + static DEFAULT_VALUE: ::std::sync::OnceLock = ::std::sync::OnceLock::new(); + let s = DEFAULT_VALUE.get_or_init(|| { let val: #ty = #val; clap::ValueEnum::to_possible_value(&val).unwrap().get_name().to_owned() }); - let s: &'static str = &*DEFAULT_VALUE; + let s: &'static str = &*s; s }) } else { quote_spanned!(attr.name.clone().span()=> { - static DEFAULT_VALUE: clap::__derive_refs::once_cell::sync::Lazy = clap::__derive_refs::once_cell::sync::Lazy::new(|| { + static DEFAULT_VALUE: ::std::sync::OnceLock = ::std::sync::OnceLock::new(); + let s = DEFAULT_VALUE.get_or_init(|| { let val: #ty = #val; ::std::string::ToString::to_string(&val) }); - let s: &'static str = &*DEFAULT_VALUE; + let s: &'static str = &*s; s }) }; @@ -643,14 +645,11 @@ impl Item { }) } - static DEFAULT_STRINGS: clap::__derive_refs::once_cell::sync::Lazy> = clap::__derive_refs::once_cell::sync::Lazy::new(|| { - iter_to_vals(#expr).collect() - }); - - static DEFAULT_VALUES: clap::__derive_refs::once_cell::sync::Lazy> = clap::__derive_refs::once_cell::sync::Lazy::new(|| { - DEFAULT_STRINGS.iter().map(::std::string::String::as_str).collect() - }); - DEFAULT_VALUES.iter().copied() + static DEFAULT_STRINGS: ::std::sync::OnceLock> = ::std::sync::OnceLock::new(); + static DEFAULT_VALUES: ::std::sync::OnceLock> = ::std::sync::OnceLock::new(); + DEFAULT_VALUES.get_or_init(|| { + DEFAULT_STRINGS.get_or_init(|| iter_to_vals(#expr).collect()).iter().map(::std::string::String::as_str).collect() + }).iter().copied() } }) } else { @@ -663,14 +662,11 @@ impl Item { iterable.into_iter().map(|val| val.borrow().to_string()) } - static DEFAULT_STRINGS: clap::__derive_refs::once_cell::sync::Lazy> = clap::__derive_refs::once_cell::sync::Lazy::new(|| { - iter_to_vals(#expr).collect() - }); - - static DEFAULT_VALUES: clap::__derive_refs::once_cell::sync::Lazy> = clap::__derive_refs::once_cell::sync::Lazy::new(|| { - DEFAULT_STRINGS.iter().map(::std::string::String::as_str).collect() - }); - DEFAULT_VALUES.iter().copied() + static DEFAULT_STRINGS: ::std::sync::OnceLock> = ::std::sync::OnceLock::new(); + static DEFAULT_VALUES: ::std::sync::OnceLock> = ::std::sync::OnceLock::new(); + DEFAULT_VALUES.get_or_init(|| { + DEFAULT_STRINGS.get_or_init(|| iter_to_vals(#expr).collect()).iter().map(::std::string::String::as_str).collect() + }).iter().copied() } }) }; @@ -707,20 +703,22 @@ impl Item { .any(|a| a.magic == Some(MagicAttrName::ValueEnum)) { quote_spanned!(attr.name.clone().span()=> { - static DEFAULT_VALUE: clap::__derive_refs::once_cell::sync::Lazy<::std::ffi::OsString> = clap::__derive_refs::once_cell::sync::Lazy::new(|| { + static DEFAULT_VALUE: ::std::sync::OnceLock = ::std::sync::OnceLock::new(); + let s = DEFAULT_VALUE.get_or_init(|| { let val: #ty = #val; clap::ValueEnum::to_possible_value(&val).unwrap().get_name().to_owned() }); - let s: &'static ::std::ffi::OsStr = &*DEFAULT_VALUE; + let s: &'static str = &*s; s }) } else { quote_spanned!(attr.name.clone().span()=> { - static DEFAULT_VALUE: clap::__derive_refs::once_cell::sync::Lazy<::std::ffi::OsString> = clap::__derive_refs::once_cell::sync::Lazy::new(|| { + static DEFAULT_VALUE: ::std::sync::OnceLock<::std::ffi::OsString> = ::std::sync::OnceLock::new(); + let s = DEFAULT_VALUE.get_or_init(|| { let val: #ty = #val; ::std::ffi::OsString::from(val) }); - let s: &'static ::std::ffi::OsStr = &*DEFAULT_VALUE; + let s: &'static ::std::ffi::OsStr = &*s; s }) }; @@ -775,14 +773,11 @@ impl Item { }) } - static DEFAULT_OS_STRINGS: clap::__derive_refs::once_cell::sync::Lazy> = clap::__derive_refs::once_cell::sync::Lazy::new(|| { - iter_to_vals(#expr).collect() - }); - - static DEFAULT_VALUES: clap::__derive_refs::once_cell::sync::Lazy> = clap::__derive_refs::once_cell::sync::Lazy::new(|| { - DEFAULT_OS_STRINGS.iter().map(::std::ffi::OsString::as_os_str).collect() - }); - DEFAULT_VALUES.iter().copied() + static DEFAULT_STRINGS: ::std::sync::OnceLock> = ::std::sync::OnceLock::new(); + static DEFAULT_VALUES: ::std::sync::OnceLock> = ::std::sync::OnceLock::new(); + DEFAULT_VALUES.get_or_init(|| { + DEFAULT_STRINGS.get_or_init(|| iter_to_vals(#expr).collect()).iter().map(::std::ffi::OsString::as_os_str).collect() + }).iter().copied() } }) } else { @@ -795,14 +790,11 @@ impl Item { iterable.into_iter().map(|val| val.borrow().into()) } - static DEFAULT_OS_STRINGS: clap::__derive_refs::once_cell::sync::Lazy> = clap::__derive_refs::once_cell::sync::Lazy::new(|| { - iter_to_vals(#expr).collect() - }); - - static DEFAULT_VALUES: clap::__derive_refs::once_cell::sync::Lazy> = clap::__derive_refs::once_cell::sync::Lazy::new(|| { - DEFAULT_OS_STRINGS.iter().map(::std::ffi::OsString::as_os_str).collect() - }); - DEFAULT_VALUES.iter().copied() + static DEFAULT_STRINGS: ::std::sync::OnceLock> = ::std::sync::OnceLock::new(); + static DEFAULT_VALUES: ::std::sync::OnceLock> = ::std::sync::OnceLock::new(); + DEFAULT_VALUES.get_or_init(|| { + DEFAULT_STRINGS.get_or_init(|| iter_to_vals(#expr).collect()).iter().map(::std::ffi::OsString::as_os_str).collect() + }).iter().copied() } }) }; diff --git a/src/lib.rs b/src/lib.rs index 10ccaf8beaf..8b8b0d36959 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -111,10 +111,3 @@ pub mod _faq; pub mod _features; #[cfg(feature = "unstable-doc")] pub mod _tutorial; - -#[doc(hidden)] -#[cfg(feature = "derive")] -pub mod __derive_refs { - #[doc(hidden)] - pub use once_cell; -}