mirror of
https://github.com/clap-rs/clap
synced 2025-01-18 23:53:54 +00:00
Apply suggestions from code review
Co-Authored-By: CreepySkeleton <creepy-skeleton@yandex.ru>
This commit is contained in:
parent
dbe6ac01f6
commit
ea637b22eb
5 changed files with 6 additions and 6 deletions
|
@ -77,7 +77,7 @@ fn lits(
|
|||
}
|
||||
|
||||
fn gen_variants(lits: &[(TokenStream, Ident)]) -> TokenStream {
|
||||
let lit = lits.iter().map(|l| l.0.clone()).collect::<Vec<_>>();
|
||||
let lit = lits.iter().map(|l| &l.0).collect::<Vec<_>>();
|
||||
|
||||
quote! {
|
||||
const VARIANTS: &'static [&'static str] = &[#(#lit),*];
|
||||
|
@ -97,7 +97,7 @@ fn gen_from_str(lits: &[(TokenStream, Ident)]) -> TokenStream {
|
|||
|
||||
match input {
|
||||
#(val if func(val, #lit) => Ok(Self::#variant),)*
|
||||
_ => Err(String::from("something went wrong parsing the value")),
|
||||
e => unreachable!("The impossible variant have been spotted: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -518,7 +518,7 @@ impl Attrs {
|
|||
)
|
||||
}
|
||||
if res.is_enum {
|
||||
abort!(field.ty, "enum is meaningless for bool")
|
||||
abort!(field.ty, "`arg_enum` is meaningless for bool")
|
||||
}
|
||||
if let Some(m) = res.find_method("default_value") {
|
||||
abort!(m.name, "default_value is meaningless for bool")
|
||||
|
|
|
@ -197,7 +197,7 @@ pub fn gen_constructor(
|
|||
let field_ty = &field.ty;
|
||||
let ci = attrs.case_insensitive();
|
||||
|
||||
quote! {
|
||||
quote_spanned! { field_ty.span()=>
|
||||
|s| <#field_ty as ::clap::ArgEnum>::from_str(s, #ci).unwrap()
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -254,7 +254,7 @@ pub fn gen_app_augmentation(
|
|||
let possible_values = if attrs.is_enum() {
|
||||
let field_ty = &field.ty;
|
||||
|
||||
quote! {
|
||||
quote_spanned! { field_ty.span()=>
|
||||
.possible_values(&<#field_ty as ::clap::ArgEnum>::VARIANTS)
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
error: enum is meaningless for bool
|
||||
error: `arg_enum` is meaningless for bool
|
||||
--> $DIR/bool_arg_enum.rs:7:11
|
||||
|
|
||||
7 | opts: bool,
|
||||
|
|
Loading…
Reference in a new issue