Skip to content

Commit

Permalink
Fix unqualified result types causing compilation failures with derive…
Browse files Browse the repository at this point in the history
… implementations
  • Loading branch information
spire-ffoston committed Dec 10, 2021
1 parent ada95d6 commit e3f80f6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clap_derive/src/derives/args.rs
Expand Up @@ -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::<Result<#convert_type, clap::Error>, _>(#parse).collect::<Result<Vec<_>, clap::Error>>())
.map(|v| v.map::<::std::result::Result<#convert_type, clap::Error>, _>(#parse).collect::<::std::result::Result<Vec<_>, clap::Error>>())
.transpose()?
.unwrap_or_else(Vec::new))
} else {
Expand All @@ -613,7 +613,7 @@ fn gen_parsers(
Ty::Vec => {
quote_spanned! { ty.span()=>
#arg_matches.#values_of(#name)
.map(|v| v.map::<Result<#convert_type, clap::Error>, _>(#parse).collect::<Result<Vec<_>, clap::Error>>())
.map(|v| v.map::<::std::result::Result<#convert_type, clap::Error>, _>(#parse).collect::<::std::result::Result<Vec<_>, clap::Error>>())
.transpose()?
.unwrap_or_else(Vec::new)
}
Expand Down
1 change: 1 addition & 0 deletions tests/derive/main.rs
Expand Up @@ -25,6 +25,7 @@ mod privacy;
mod raw_bool_literal;
mod raw_idents;
mod rename_all_env;
mod result_type_alias_regression;
mod skip;
mod structopt;
mod subcommands;
Expand Down
15 changes: 15 additions & 0 deletions tests/derive/result_type_alias_regression.rs
@@ -0,0 +1,15 @@
/// Regression test to ensure that Result type aliases do not cause compilation failures.
use clap::Parser;

#[allow(dead_code)]
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;

#[derive(Debug, Parser)]
pub struct Opts {
strings: Vec<String>,
}

#[test]
fn result_type_alias_regression() {
Opts::parse();
}

0 comments on commit e3f80f6

Please sign in to comment.