From c3fa807503d2372a7d6faad64c172b52a8fcf9af Mon Sep 17 00:00:00 2001 From: Stiopa Koltsov Date: Sun, 26 Jun 2022 00:44:58 +0100 Subject: [PATCH] refactor: Put once_cell reexport into __macro_refs When upgrading our company projects from clap 3.1 to clap 3.2 I had to fix several references to `clap::lazy_init`. People are not supposed to do that, but that's hard to enforce. Hope placing `once_cell` reexport into `__macro_refs` prevent at least some of the such issues in the future. --- clap_derive/src/attrs.rs | 4 ++-- src/lib.rs | 7 +++++-- src/macros.rs | 6 ++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/clap_derive/src/attrs.rs b/clap_derive/src/attrs.rs index 3c685fbe86cb..b9e01b0c827a 100644 --- a/clap_derive/src/attrs.rs +++ b/clap_derive/src/attrs.rs @@ -552,7 +552,7 @@ impl Attrs { }) } else { quote_spanned!(ident.span()=> { - static DEFAULT_VALUE: clap::once_cell::sync::Lazy = clap::once_cell::sync::Lazy::new(|| { + static DEFAULT_VALUE: clap::__macro_refs::once_cell::sync::Lazy = clap::__macro_refs::once_cell::sync::Lazy::new(|| { let val: #ty = #val; ::std::string::ToString::to_string(&val) }); @@ -592,7 +592,7 @@ impl Attrs { }) } else { quote_spanned!(ident.span()=> { - static DEFAULT_VALUE: clap::once_cell::sync::Lazy<::std::ffi::OsString> = clap::once_cell::sync::Lazy::new(|| { + static DEFAULT_VALUE: clap::__macro_refs::once_cell::sync::Lazy<::std::ffi::OsString> = clap::__macro_refs::once_cell::sync::Lazy::new(|| { let val: #ty = #val; ::std::ffi::OsString::from(val) }); diff --git a/src/lib.rs b/src/lib.rs index d9a97715fb67..187aad13678c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -82,9 +82,12 @@ pub use Parser as StructOpt; )] pub use ValueEnum as ArgEnum; -#[cfg(any(feature = "derive", feature = "cargo"))] #[doc(hidden)] -pub use once_cell; +pub mod __macro_refs { + #[cfg(any(feature = "derive", feature = "cargo"))] + #[doc(hidden)] + pub use once_cell; +} #[macro_use] #[allow(missing_docs)] diff --git a/src/macros.rs b/src/macros.rs index 953ae03e6983..1f9167408705 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -250,8 +250,10 @@ macro_rules! crate_version { #[macro_export] macro_rules! crate_authors { ($sep:expr) => {{ - static CACHED: clap::once_cell::sync::Lazy = - clap::once_cell::sync::Lazy::new(|| env!("CARGO_PKG_AUTHORS").replace(':', $sep)); + static CACHED: clap::__macro_refs::once_cell::sync::Lazy = + clap::__macro_refs::once_cell::sync::Lazy::new(|| { + env!("CARGO_PKG_AUTHORS").replace(':', $sep) + }); let s: &'static str = &*CACHED; s