diff --git a/clap_derive/src/derives/args.rs b/clap_derive/src/derives/args.rs index 016a3d8f..2842b9ba 100644 --- a/clap_derive/src/derives/args.rs +++ b/clap_derive/src/derives/args.rs @@ -602,7 +602,7 @@ fn gen_parsers( Ty::OptionVec => quote_spanned! { ty.span()=> if #arg_matches.is_present(#name) { Some(#arg_matches.#values_of(#name) - .map(|v| v.map::, _>(#parse).collect::, clap::Error>>()) + .map(|v| v.map::<::std::result::Result<#convert_type, clap::Error>, _>(#parse).collect::<::std::result::Result, clap::Error>>()) .transpose()? .unwrap_or_else(Vec::new)) } else { @@ -613,7 +613,7 @@ fn gen_parsers( Ty::Vec => { quote_spanned! { ty.span()=> #arg_matches.#values_of(#name) - .map(|v| v.map::, _>(#parse).collect::, clap::Error>>()) + .map(|v| v.map::<::std::result::Result<#convert_type, clap::Error>, _>(#parse).collect::<::std::result::Result, clap::Error>>()) .transpose()? .unwrap_or_else(Vec::new) } diff --git a/tests/derive/main.rs b/tests/derive/main.rs index 0ef1ee45..33ce6715 100644 --- a/tests/derive/main.rs +++ b/tests/derive/main.rs @@ -28,5 +28,6 @@ mod rename_all_env; mod skip; mod structopt; mod subcommands; +mod type_alias_regressions; mod utf8; mod utils; diff --git a/tests/derive/type_alias_regressions.rs b/tests/derive/type_alias_regressions.rs new file mode 100644 index 00000000..16670587 --- /dev/null +++ b/tests/derive/type_alias_regressions.rs @@ -0,0 +1,31 @@ +/// Regression test to ensure that type aliases do not cause compilation failures. +use clap::Parser; +use std::str::FromStr; + +// Result type alias +#[allow(dead_code)] +type Result = std::result::Result>; + +// Wrapper to use for Option type alias +struct Wrapper(T); + +impl FromStr for Wrapper { + type Err = ::Err; + + fn from_str(s: &str) -> std::result::Result { + T::from_str(s).map(Wrapper) + } +} + +type Option = std::option::Option>; + +#[derive(Parser)] +pub struct Opts { + another_string: Option, + strings: Vec, +} + +#[test] +fn type_alias_regressions() { + Opts::parse(); +}