Skip to content

Commit

Permalink
refactor: Put once_cell reexport into __macro_refs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stepancheg committed Jun 26, 2022
1 parent b2779f2 commit 464ef39
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions clap_derive/src/attrs.rs
Expand Up @@ -552,7 +552,7 @@ impl Attrs {
})
} else {
quote_spanned!(ident.span()=> {
static DEFAULT_VALUE: clap::once_cell::sync::Lazy<String> = clap::once_cell::sync::Lazy::new(|| {
static DEFAULT_VALUE: clap::__macro_refs::once_cell::sync::Lazy<String> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
let val: #ty = #val;
::std::string::ToString::to_string(&val)
});
Expand Down Expand Up @@ -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)
});
Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Expand Up @@ -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)]
Expand Down
6 changes: 4 additions & 2 deletions src/macros.rs
Expand Up @@ -250,8 +250,10 @@ macro_rules! crate_version {
#[macro_export]
macro_rules! crate_authors {
($sep:expr) => {{
static CACHED: clap::once_cell::sync::Lazy<String> =
clap::once_cell::sync::Lazy::new(|| env!("CARGO_PKG_AUTHORS").replace(':', $sep));
static CACHED: clap::__macro_refs::once_cell::sync::Lazy<String> =
clap::__macro_refs::once_cell::sync::Lazy::new(|| {
env!("CARGO_PKG_AUTHORS").replace(':', $sep)
});

let s: &'static str = &*CACHED;
s
Expand Down
4 changes: 2 additions & 2 deletions tests/derive_ui/next/bool_value_enum.stderr
@@ -1,8 +1,8 @@
error[E0277]: the trait bound `bool: ValueEnum` is not satisfied
error[E0277]: the trait bound `bool: ArgEnum` is not satisfied
--> tests/derive_ui/next/bool_value_enum.rs:6:31
|
6 | #[clap(short, value_enum, default_value_t)]
| ^^^^^^^^^^^^^^^ the trait `ValueEnum` is not implemented for `bool`
| ^^^^^^^^^^^^^^^ the trait `ArgEnum` is not implemented for `bool`
|
note: required by `to_possible_value`
--> src/derive.rs
Expand Down

0 comments on commit 464ef39

Please sign in to comment.