@@ -16,7 +16,7 @@ use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
1616use quote:: { quote, ToTokens } ;
1717use syn:: {
1818 parse:: { Parse , ParseStream , Parser as _} ,
19- parse_macro_input,
19+ parse_macro_input, parse_quote ,
2020 token:: DotDot ,
2121 Expr , ExprCall , Pat , Token ,
2222} ;
@@ -131,7 +131,9 @@ fn into_match_pattern_expr(stream: TokenStream) -> syn::Result<TokenStream> {
131131 Pat :: parse_multi. parse2 ( stream. clone ( ) ) ?;
132132 Ok ( quote ! {
133133 googletest:: matchers:: __internal_unstable_do_not_depend_on_these:: pattern_only(
134- |v| matches!( v, #stream) ,
134+ |v| {
135+ matches!( v, #stream)
136+ } ,
135137 concat!( "is " , stringify!( #stream) ) ,
136138 concat!( "is not " , stringify!( #stream) ) )
137139 } )
@@ -140,8 +142,7 @@ fn into_match_pattern_expr(stream: TokenStream) -> syn::Result<TokenStream> {
140142////////////////////////////////////////////////////////////////////////////////
141143// Parse tuple struct patterns
142144
143- /// Each part in a tuple matcher pattern that's between the commas. When `None`,
144- /// it represents `_` which matches anything.
145+ /// Each part in a tuple matcher pattern that's between the commas.
145146struct MaybeTupleFieldPattern ( Option < TupleFieldPattern > ) ;
146147
147148struct TupleFieldPattern {
@@ -152,7 +153,7 @@ struct TupleFieldPattern {
152153impl Parse for MaybeTupleFieldPattern {
153154 fn parse ( input : ParseStream ) -> syn:: Result < Self > {
154155 let pattern = match input. parse :: < Option < Token ! [ _] > > ( ) ? {
155- Some ( _) => None ,
156+ Some ( _) => Some ( TupleFieldPattern { ref_token : None , matcher : parse_quote ! ( _ ) } ) ,
156157 None => Some ( TupleFieldPattern { ref_token : input. parse ( ) ?, matcher : input. parse ( ) ? } ) ,
157158 } ;
158159 Ok ( MaybeTupleFieldPattern ( pattern) )
@@ -173,7 +174,13 @@ fn parse_tuple_pattern_args(
173174 . filter_map ( |( index, maybe_pattern) | maybe_pattern. 0 . map ( |pattern| ( index, pattern) ) )
174175 . map ( |( index, TupleFieldPattern { ref_token, matcher } ) | {
175176 let index = syn:: Index :: from ( index) ;
176- quote ! { googletest:: matchers:: field!( #struct_name. #index, #ref_token #matcher) }
177+ // `_` matches anything, so we can use anything as the matcher.
178+ let matcher_to_use = if matches ! ( syn:: parse2:: <Expr >( quote! { #matcher} ) , Ok ( parsed_matcher) if parsed_matcher == parse_quote!( _) ) {
179+ quote ! { googletest:: matchers:: anything( ) }
180+ } else {
181+ quote ! { #matcher }
182+ } ;
183+ quote ! { googletest:: matchers:: field!( #struct_name. #index, #ref_token #matcher_to_use) }
177184 } ) ;
178185
179186 let matcher = quote ! {
0 commit comments