@@ -142,19 +142,36 @@ fn return_original_snippet_with_failure_marked(
142142    Some ( context. snippet ( span) . to_owned ( ) ) 
143143} 
144144
145+ struct  InsideMacroGuard < ' a >  { 
146+     context :  & ' a  RewriteContext < ' a > , 
147+     is_nested :  bool , 
148+ } 
149+ 
150+ impl < ' a >  InsideMacroGuard < ' a >  { 
151+     fn  inside_macro_context ( context :  & ' a  RewriteContext )  -> InsideMacroGuard < ' a >  { 
152+         let  is_nested = context. inside_macro . replace ( true ) ; 
153+         InsideMacroGuard  {  context,  is_nested } 
154+     } 
155+ } 
156+ 
157+ impl < ' a >  Drop  for  InsideMacroGuard < ' a >  { 
158+     fn  drop ( & mut  self )  { 
159+         self . context . inside_macro . replace ( self . is_nested ) ; 
160+     } 
161+ } 
162+ 
145163pub  fn  rewrite_macro ( 
146164    mac :  & ast:: Mac , 
147165    extra_ident :  Option < ast:: Ident > , 
148166    context :  & RewriteContext , 
149167    shape :  Shape , 
150168    position :  MacroPosition , 
151169)  -> Option < String >  { 
152-     context . inside_macro . replace ( true ) ; 
153-     let  result = rewrite_macro_inner ( mac,  extra_ident,  context,  shape,  position) ; 
170+     let  guard =  InsideMacroGuard :: inside_macro_context ( context ) ; 
171+     let  result = rewrite_macro_inner ( mac,  extra_ident,  context,  shape,  position,  guard . is_nested ) ; 
154172    if  result. is_none ( )  { 
155173        context. macro_rewrite_failure . replace ( true ) ; 
156174    } 
157-     context. inside_macro . replace ( false ) ; 
158175    result
159176} 
160177
@@ -164,6 +181,7 @@ pub fn rewrite_macro_inner(
164181    context :  & RewriteContext , 
165182    shape :  Shape , 
166183    position :  MacroPosition , 
184+     is_nested_macro :  bool , 
167185)  -> Option < String >  { 
168186    if  context. config . use_try_shorthand ( )  { 
169187        if  let  Some ( expr)  = convert_try_mac ( mac,  context)  { 
@@ -176,7 +194,7 @@ pub fn rewrite_macro_inner(
176194
177195    let  macro_name = rewrite_macro_name ( context,  & mac. node . path ,  extra_ident) ; 
178196
179-     let  style = if  FORCED_BRACKET_MACROS . contains ( & & macro_name[ ..] )  { 
197+     let  style = if  FORCED_BRACKET_MACROS . contains ( & & macro_name[ ..] )  && !is_nested_macro  { 
180198        DelimToken :: Bracket 
181199    }  else  { 
182200        original_style
@@ -309,7 +327,7 @@ pub fn rewrite_macro_inner(
309327                }  else  { 
310328                    Some ( SeparatorTactic :: Never ) 
311329                } ; 
312-                 if  FORCED_BRACKET_MACROS . contains ( macro_name)  { 
330+                 if  FORCED_BRACKET_MACROS . contains ( macro_name)  && !is_nested_macro  { 
313331                    context. inside_macro . replace ( false ) ; 
314332                    if  context. use_block_indent ( )  { 
315333                        force_trailing_comma = Some ( SeparatorTactic :: Vertical ) ; 
0 commit comments