Merge pull request #3142 from spire-ffoston/fix-result-type-alias-derive-impl

Fix unqualified result types causing compilation failures with derive implementations
This commit is contained in:
Pavan Kumar Sunkara 2021-12-10 16:26:16 +00:00 committed by GitHub
commit 0eda43d0f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 2 deletions

View file

@ -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 {
@ -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)
}

View file

@ -28,5 +28,6 @@ mod rename_all_env;
mod skip;
mod structopt;
mod subcommands;
mod type_alias_regressions;
mod utf8;
mod utils;

View file

@ -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();
}