@@ -190,22 +190,27 @@ pub enum ToolItem {
190
190
191
191
impl Parse for ToolItem {
192
192
fn parse ( input : syn:: parse:: ParseStream ) -> syn:: Result < Self > {
193
- let lookahead = input. lookahead1 ( ) ;
194
- if lookahead. peek ( Token ! [ impl ] ) {
195
- let item = input. parse :: < ItemImpl > ( ) ?;
196
- Ok ( ToolItem :: Impl ( item) )
197
- } else {
198
- let item = input. parse :: < ItemFn > ( ) ?;
199
- Ok ( ToolItem :: Fn ( item) )
193
+ if let Ok ( item) =input. parse :: < ItemImpl > ( ) {
194
+ return Ok ( ToolItem :: Impl ( item) ) ;
195
+ }
196
+ if let Ok ( item) = input. parse :: < ItemFn > ( ) {
197
+ return Ok ( ToolItem :: Fn ( item) ) ;
200
198
}
199
+ Err ( syn:: Error :: new (
200
+ input. span ( ) ,
201
+ "expected function or impl block" ,
202
+ ) )
201
203
}
202
204
}
203
205
204
206
// dispatch impl function item and impl block item
205
207
pub ( crate ) fn tool ( attr : TokenStream , input : TokenStream ) -> syn:: Result < TokenStream > {
206
208
let tool_item = syn:: parse2 :: < ToolItem > ( input) ?;
207
209
match tool_item {
208
- ToolItem :: Fn ( item) => tool_fn_item ( attr, item) ,
210
+ ToolItem :: Fn ( item) => {
211
+ println ! ( "{:#?}" , & item) ;
212
+ tool_fn_item ( attr, item)
213
+ } ,
209
214
ToolItem :: Impl ( item) => tool_impl_item ( attr, item) ,
210
215
}
211
216
}
@@ -225,7 +230,6 @@ pub(crate) fn tool_impl_item(attr: TokenStream, mut input: ItemImpl) -> syn::Res
225
230
. filter_map ( extract_doc_line)
226
231
. collect :: < Vec < _ > > ( )
227
232
. join ( "\n " ) ;
228
-
229
233
parse_quote ! {
230
234
#doc_content. trim( ) . to_string( )
231
235
}
0 commit comments