Upgrade rust/crates/structopt-derive to 0.4.13 Test: make Change-Id: I041d50a4e492974710b8bc993baca196554bd370
diff --git a/src/ty.rs b/src/ty.rs old mode 100644 new mode 100755 index 89d8b00..ad3acd9 --- a/src/ty.rs +++ b/src/ty.rs
@@ -63,6 +63,8 @@ where F: FnOnce(&PathSegment) -> bool, { + let ty = strip_group(ty); + only_last_segment(ty) .filter(|segment| f(segment)) .and_then(|segment| { @@ -85,6 +87,8 @@ } pub fn is_simple_ty(ty: &syn::Type, name: &str) -> bool { + let ty = strip_group(ty); + only_last_segment(ty) .map(|segment| { if let PathArguments::None = segment.arguments { @@ -96,6 +100,23 @@ .unwrap_or(false) } +// If the struct is placed inside of a macro_rules! declaration, +// in some circumstances, the tokens inside will be enclosed +// in `proc_macro::Group` delimited by invisible `proc_macro::Delimiter::None`. +// +// In syn speak, this is encoded via `*::Group` variants. We don't really care about +// that, so let's just strip it. +// +// Details: https://doc.rust-lang.org/proc_macro/enum.Delimiter.html#variant.None +// See also: https://github.com/TeXitoi/structopt/issues/439 +fn strip_group(mut ty: &syn::Type) -> &syn::Type { + while let Type::Group(group) = ty { + ty = &*group.elem; + } + + ty +} + fn is_generic_ty(ty: &syn::Type, name: &str) -> bool { subty_if_name(ty, name).is_some() }