@@ -142,19 +142,36 @@ fn return_original_snippet_with_failure_marked(
142
142
Some ( context. snippet ( span) . to_owned ( ) )
143
143
}
144
144
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
+
145
163
pub fn rewrite_macro (
146
164
mac : & ast:: Mac ,
147
165
extra_ident : Option < ast:: Ident > ,
148
166
context : & RewriteContext ,
149
167
shape : Shape ,
150
168
position : MacroPosition ,
151
169
) -> 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 ) ;
154
172
if result. is_none ( ) {
155
173
context. macro_rewrite_failure . replace ( true ) ;
156
174
}
157
- context. inside_macro . replace ( false ) ;
158
175
result
159
176
}
160
177
@@ -164,6 +181,7 @@ pub fn rewrite_macro_inner(
164
181
context : & RewriteContext ,
165
182
shape : Shape ,
166
183
position : MacroPosition ,
184
+ is_nested_macro : bool ,
167
185
) -> Option < String > {
168
186
if context. config . use_try_shorthand ( ) {
169
187
if let Some ( expr) = convert_try_mac ( mac, context) {
@@ -176,7 +194,7 @@ pub fn rewrite_macro_inner(
176
194
177
195
let macro_name = rewrite_macro_name ( context, & mac. node . path , extra_ident) ;
178
196
179
- let style = if FORCED_BRACKET_MACROS . contains ( & & macro_name[ ..] ) {
197
+ let style = if FORCED_BRACKET_MACROS . contains ( & & macro_name[ ..] ) && !is_nested_macro {
180
198
DelimToken :: Bracket
181
199
} else {
182
200
original_style
@@ -309,7 +327,7 @@ pub fn rewrite_macro_inner(
309
327
} else {
310
328
Some ( SeparatorTactic :: Never )
311
329
} ;
312
- if FORCED_BRACKET_MACROS . contains ( macro_name) {
330
+ if FORCED_BRACKET_MACROS . contains ( macro_name) && !is_nested_macro {
313
331
context. inside_macro . replace ( false ) ;
314
332
if context. use_block_indent ( ) {
315
333
force_trailing_comma = Some ( SeparatorTactic :: Vertical ) ;
0 commit comments