Skip to content

Commit

Permalink
Merge pull request #4096 from epage/raw
Browse files Browse the repository at this point in the history
fix: Switch to owned OsStr type
  • Loading branch information
epage committed Aug 19, 2022
2 parents e81b1aa + 429143a commit 99d3bb8
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 102 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -69,7 +69,7 @@ suggestions = ["dep:strsim"]

# Optional
deprecated = ["clap_derive?/deprecated"] # Guided experience to prepare for next breaking release (at different stages of development, this may become default)
derive = ["clap_derive", "dep:once_cell"]
derive = ["clap_derive"]
cargo = ["dep:once_cell"] # Disable if you're not using Cargo, enables Cargo-env-var-dependent macros
wrap_help = ["dep:terminal_size", "textwrap/terminal_size"]
env = [] # Use environment variables during arg parsing
Expand Down
38 changes: 8 additions & 30 deletions clap_derive/src/attrs.rs
Expand Up @@ -504,11 +504,10 @@ impl Attrs {
})
} else {
quote_spanned!(ident.span()=> {
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)
});
&*DEFAULT_VALUE
}
})
};

Expand Down Expand Up @@ -558,10 +557,7 @@ impl Attrs {

}

static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy<Vec<&str>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
iter_to_vals(#expr)
});
DEFAULT_VALUES.iter().copied()
iter_to_vals(#expr)
}
})
} else {
Expand All @@ -575,14 +571,7 @@ impl Attrs {

}

static DEFAULT_STRINGS: clap::__macro_refs::once_cell::sync::Lazy<Vec<::std::string::String>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
iter_to_vals(#expr)
});

static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy<Vec<&str>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
DEFAULT_STRINGS.iter().map(::std::string::String::as_str).collect()
});
DEFAULT_VALUES.iter().copied()
iter_to_vals(#expr)
}
})
};
Expand Down Expand Up @@ -619,11 +608,10 @@ impl Attrs {
})
} else {
quote_spanned!(ident.span()=> {
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)
});
&*DEFAULT_VALUE
}
})
};

Expand Down Expand Up @@ -674,10 +662,7 @@ impl Attrs {

}

static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy<Vec<&::std::ffi::OsStr>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
iter_to_vals(#expr)
});
DEFAULT_VALUES.iter().copied()
iter_to_vals(#expr)
}
})
} else {
Expand All @@ -691,14 +676,7 @@ impl Attrs {

}

static DEFAULT_OS_STRINGS: clap::__macro_refs::once_cell::sync::Lazy<Vec<::std::ffi::OsString>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
iter_to_vals(#expr)
});

static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy<Vec<&::std::ffi::OsStr>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
DEFAULT_OS_STRINGS.iter().map(::std::ffi::OsString::as_os_str).collect()
});
DEFAULT_VALUES.iter().copied()
iter_to_vals(#expr)
}
})
};
Expand Down

0 comments on commit 99d3bb8

Please sign in to comment.