Skip to content

Commit 65f9e0d

Browse files
committed
refactor(derive): Clean up unnecessary noop parsing
My guess is this was left over from switching to using the type based API. The generated code for extracting values from `ArgMatches` had some code that didn't actually do anything, like mapping over the identity function, and wrapping a value in an `Ok` only to immediately use "?" on it.
1 parent 5345d6c commit 65f9e0d

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

clap_derive/src/derives/args.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,6 @@ fn gen_parsers(
643643
let get_one = quote_spanned!(span=> remove_one::<#convert_type>);
644644
let get_many = quote_spanned!(span=> remove_many::<#convert_type>);
645645
let get_occurrences = quote_spanned!(span=> remove_occurrences::<#convert_type>);
646-
let deref = quote!(|s| s);
647-
let parse = quote_spanned!(span=> |s| ::std::result::Result::Ok::<_, clap::Error>(s));
648646

649647
// Give this identifier the same hygiene
650648
// as the `arg_matches` parameter definition. This
@@ -661,18 +659,13 @@ fn gen_parsers(
661659
Ty::Option => {
662660
quote_spanned! { ty.span()=>
663661
#arg_matches.#get_one(#id)
664-
.map(#deref)
665-
.map(#parse)
666-
.transpose()?
667662
}
668663
}
669664

670665
Ty::OptionOption => quote_spanned! { ty.span()=>
671666
if #arg_matches.contains_id(#id) {
672667
Some(
673668
#arg_matches.#get_one(#id)
674-
.map(#deref)
675-
.map(#parse).transpose()?
676669
)
677670
} else {
678671
None
@@ -682,8 +675,7 @@ fn gen_parsers(
682675
Ty::OptionVec => quote_spanned! { ty.span()=>
683676
if #arg_matches.contains_id(#id) {
684677
Some(#arg_matches.#get_many(#id)
685-
.map(|v| v.map(#deref).map::<::std::result::Result<#convert_type, clap::Error>, _>(#parse).collect::<::std::result::Result<Vec<_>, clap::Error>>())
686-
.transpose()?
678+
.map(|v| v.collect::<Vec<_>>())
687679
.unwrap_or_else(Vec::new))
688680
} else {
689681
None
@@ -693,8 +685,7 @@ fn gen_parsers(
693685
Ty::Vec => {
694686
quote_spanned! { ty.span()=>
695687
#arg_matches.#get_many(#id)
696-
.map(|v| v.map(#deref).map::<::std::result::Result<#convert_type, clap::Error>, _>(#parse).collect::<::std::result::Result<Vec<_>, clap::Error>>())
697-
.transpose()?
688+
.map(|v| v.collect::<Vec<_>>())
698689
.unwrap_or_else(Vec::new)
699690
}
700691
}
@@ -713,9 +704,7 @@ fn gen_parsers(
713704
Ty::Other => {
714705
quote_spanned! { ty.span()=>
715706
#arg_matches.#get_one(#id)
716-
.map(#deref)
717-
.ok_or_else(|| clap::Error::raw(clap::error::ErrorKind::MissingRequiredArgument, format!("The following required argument was not provided: {}", #id)))
718-
.and_then(#parse)?
707+
.ok_or_else(|| clap::Error::raw(clap::error::ErrorKind::MissingRequiredArgument, format!("The following required argument was not provided: {}", #id)))?
719708
}
720709
}
721710
};

0 commit comments

Comments
 (0)