@@ -139,22 +139,21 @@ fn handle_function_macro(
139
139
tokens : & [ clang:: ClangToken ] ,
140
140
callbacks : & dyn crate :: callbacks:: ParseCallbacks ,
141
141
) -> Result < ( ) , ParseError > {
142
+ let mut spelled =
143
+ tokens. into_iter ( ) . map ( clang:: ClangToken :: spelling) ;
144
+ let boundary = spelled
145
+ . clone ( ) // clone the iterator to avoid consuming elements
146
+ . position ( |s| s == b")" ) ;
147
+
142
148
// cexpr explicitly does not handle function-like macros, except for a
143
149
// degenerate case in which it behaves in a non-conformant way. We prevent
144
150
// cexpr from ever seeing function-like macros by checking for a parenthesis
145
151
// token immediately adjacent to (that is, abutting) the first token in the
146
152
// macro definition.
147
- match tokens. get ( 0 ..2 ) {
148
- Some ( [ first, second] )
153
+ match ( tokens. get ( 0 ..2 ) , boundary ) {
154
+ ( Some ( [ first, second] ) , Some ( boundary ) )
149
155
if first. is_abutting ( & second) && second. spelling ( ) == b"(" =>
150
156
{
151
- let mut spelled =
152
- tokens. into_iter ( ) . map ( clang:: ClangToken :: spelling) ;
153
- let boundary = spelled
154
- . clone ( ) // clone the iterator to avoid consuming elements
155
- . position ( |s| s == b")" )
156
- . unwrap_or ( joined. len ( ) ) ;
157
-
158
157
// Add 1, to convert index to length.
159
158
let left = spelled. by_ref ( ) . take ( boundary + 1 ) ;
160
159
let left = left. collect :: < Vec < _ > > ( ) . concat ( ) ;
0 commit comments