Skip to content

Commit

Permalink
fix: unqualified result types causing compilation failures with deriv…
Browse files Browse the repository at this point in the history
…e implementations
  • Loading branch information
spire-ffoston committed Dec 10, 2021
1 parent ada95d6 commit 746ff3e
Show file tree
Hide file tree
Showing 3 changed files with 34 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 type_alias_regressions;
mod skip;
mod structopt;
mod subcommands;
Expand Down
31 changes: 31 additions & 0 deletions 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<T> = std::result::Result<T, Box<dyn std::error::Error>>;

// Wrapper to use for Option type alias
struct Wrapper<T>(T);

impl<T: FromStr> FromStr for Wrapper<T> {
type Err = <T as FromStr>::Err;

fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
T::from_str(s).map(Wrapper)
}
}

type Option<T> = std::option::Option<Wrapper<T>>;

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

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

0 comments on commit 746ff3e

Please sign in to comment.