@@ -262,8 +262,13 @@ fn rewrite_macro_inner(
262262 original_style
263263 } ;
264264
265- let ts: TokenStream = mac. stream ( ) ;
266- let has_comment = contains_comment ( context. snippet ( mac. span ) ) ;
265+ let ts: TokenStream = match * mac. args {
266+ ast:: MacArgs :: Empty => TokenStream :: default ( ) ,
267+ ast:: MacArgs :: Delimited ( _, _, token_stream) => token_stream,
268+ ast:: MacArgs :: Eq ( _, token_stream) => token_stream,
269+ } ;
270+
271+ let has_comment = contains_comment ( context. snippet ( mac. span ( ) ) ) ;
267272 if ts. is_empty ( ) && !has_comment {
268273 return match style {
269274 DelimToken :: Paren if position == MacroPosition :: Item => {
@@ -297,7 +302,7 @@ fn rewrite_macro_inner(
297302 } else if let Some ( arg) = parse_macro_arg ( & mut parser) {
298303 arg_vec. push ( arg) ;
299304 } else {
300- return return_macro_parse_failure_fallback ( context, shape. indent , mac. span ) ;
305+ return return_macro_parse_failure_fallback ( context, shape. indent , mac. span ( ) ) ;
301306 }
302307
303308 match parser. token . kind {
@@ -321,16 +326,16 @@ fn rewrite_macro_inner(
321326 return return_macro_parse_failure_fallback (
322327 context,
323328 shape. indent ,
324- mac. span ,
329+ mac. span ( ) ,
325330 ) ;
326331 }
327332 }
328333 }
329334 }
330- return return_macro_parse_failure_fallback ( context, shape. indent , mac. span ) ;
335+ return return_macro_parse_failure_fallback ( context, shape. indent , mac. span ( ) ) ;
331336 }
332337 _ if arg_vec. last ( ) . map_or ( false , MacroArg :: is_item) => continue ,
333- _ => return return_macro_parse_failure_fallback ( context, shape. indent , mac. span ) ,
338+ _ => return return_macro_parse_failure_fallback ( context, shape. indent , mac. span ( ) ) ,
334339 }
335340
336341 parser. bump ( ) ;
@@ -350,7 +355,7 @@ fn rewrite_macro_inner(
350355 shape,
351356 style,
352357 position,
353- mac. span ,
358+ mac. span ( ) ,
354359 ) ;
355360 }
356361
@@ -367,7 +372,7 @@ fn rewrite_macro_inner(
367372 & macro_name,
368373 arg_vec. iter ( ) ,
369374 shape,
370- mac. span ,
375+ mac. span ( ) ,
371376 context. config . width_heuristics ( ) . fn_call_width ,
372377 if trailing_comma {
373378 Some ( SeparatorTactic :: Always )
@@ -404,7 +409,7 @@ fn rewrite_macro_inner(
404409 let rewrite = rewrite_array (
405410 macro_name,
406411 arg_vec. iter ( ) ,
407- mac. span ,
412+ mac. span ( ) ,
408413 context,
409414 shape,
410415 force_trailing_comma,
@@ -422,7 +427,7 @@ fn rewrite_macro_inner(
422427 // For macro invocations with braces, always put a space between
423428 // the `macro_name!` and `{ /* macro_body */ }` but skip modifying
424429 // anything in between the braces (for now).
425- let snippet = context. snippet ( mac. span ) . trim_start_matches ( |c| c != '{' ) ;
430+ let snippet = context. snippet ( mac. span ( ) ) . trim_start_matches ( |c| c != '{' ) ;
426431 match trim_left_preserve_layout ( snippet, shape. indent , & context. config ) {
427432 Some ( macro_body) => Some ( format ! ( "{} {}" , macro_name, macro_body) ) ,
428433 None => Some ( format ! ( "{} {}" , macro_name, snippet) ) ,
@@ -486,8 +491,12 @@ pub(crate) fn rewrite_macro_def(
486491 if snippet. as_ref ( ) . map_or ( true , |s| s. ends_with ( ';' ) ) {
487492 return snippet;
488493 }
489-
490- let mut parser = MacroParser :: new ( def. stream ( ) . into_trees ( ) ) ;
494+ let ts: TokenStream = match * def. body {
495+ ast:: MacArgs :: Empty => TokenStream :: default ( ) ,
496+ ast:: MacArgs :: Delimited ( _, _, token_stream) => token_stream,
497+ ast:: MacArgs :: Eq ( _, token_stream) => token_stream,
498+ } ;
499+ let mut parser = MacroParser :: new ( ts. into_trees ( ) ) ;
491500 let parsed_def = match parser. parse ( ) {
492501 Some ( def) => def,
493502 None => return snippet,
@@ -1192,17 +1201,21 @@ pub(crate) fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext<'_>) -> O
11921201 // https://github.com/rust-lang/rust/pull/62672
11931202 let path = & pprust:: path_to_string ( & mac. path ) ;
11941203 if path == "try" || path == "r#try" {
1195- let ts: TokenStream = mac. tts . clone ( ) ;
1204+ let ts: TokenStream = match * mac. args {
1205+ ast:: MacArgs :: Empty => TokenStream :: default ( ) ,
1206+ ast:: MacArgs :: Delimited ( _, _, token_stream) => token_stream,
1207+ ast:: MacArgs :: Eq ( _, token_stream) => token_stream,
1208+ } ;
11961209 let mut parser = new_parser_from_tts ( context. parse_sess . inner ( ) , ts. trees ( ) . collect ( ) ) ;
11971210
11981211 let mut kind = parser. parse_expr ( ) . ok ( ) ?;
11991212 // take the end pos of mac so that the Try expression includes the closing parenthesis of
12001213 // the try! macro
1201- kind. span = mk_sp ( kind. span . lo ( ) , mac. span . hi ( ) ) ;
1214+ kind. span = mk_sp ( kind. span . lo ( ) , mac. span ( ) . hi ( ) ) ;
12021215 Some ( ast:: Expr {
12031216 id : ast:: NodeId :: root ( ) , // dummy value
12041217 kind : ast:: ExprKind :: Try ( kind) ,
1205- span : mac. span , // incorrect span, but shouldn't matter too much
1218+ span : mac. span ( ) , // incorrect span, but shouldn't matter too much
12061219 attrs : ast:: AttrVec :: new ( ) ,
12071220 } )
12081221 } else {
@@ -1211,7 +1224,7 @@ pub(crate) fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext<'_>) -> O
12111224}
12121225
12131226fn macro_style ( mac : & ast:: Mac , context : & RewriteContext < ' _ > ) -> DelimToken {
1214- let snippet = context. snippet ( mac. span ) ;
1227+ let snippet = context. snippet ( mac. span ( ) ) ;
12151228 let paren_pos = snippet. find_uncommented ( "(" ) . unwrap_or ( usize:: max_value ( ) ) ;
12161229 let bracket_pos = snippet. find_uncommented ( "[" ) . unwrap_or ( usize:: max_value ( ) ) ;
12171230 let brace_pos = snippet. find_uncommented ( "{" ) . unwrap_or ( usize:: max_value ( ) ) ;
0 commit comments