1- use  std:: ops:: Deref ; 
1+ use  std:: ops:: { Deref ,   DerefMut } ; 
22use  std:: path:: PathBuf ; 
33use  std:: rc:: Rc ; 
44use  std:: { iter,  mem} ; 
@@ -594,6 +594,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
594594                cx :  self . cx , 
595595                invocations :  Vec :: new ( ) , 
596596                monotonic :  self . monotonic , 
597+                 expr_under_let_init_else :  false , 
597598            } ; 
598599            fragment. mut_visit_with ( & mut  collector) ; 
599600            fragment. add_placeholders ( extra_placeholders) ; 
@@ -1771,6 +1772,7 @@ struct InvocationCollector<'a, 'b> {
17711772    cx :  & ' a  mut  ExtCtxt < ' b > , 
17721773    invocations :  Vec < ( Invocation ,  Option < Lrc < SyntaxExtension > > ) > , 
17731774    monotonic :  bool , 
1775+     expr_under_let_init_else :  bool , 
17741776} 
17751777
17761778impl < ' a ,  ' b >  InvocationCollector < ' a ,  ' b >  { 
@@ -2167,6 +2169,35 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
21672169        self . flat_map_node ( node) 
21682170    } 
21692171
2172+     fn  visit_local ( & mut  self ,  local :  & mut  P < rustc_ast:: Local > )  { 
2173+         let  ast:: Local  {  id,  pat,  ty,  kind,  span,  colon_sp,  attrs,  tokens }  = local. deref_mut ( ) ; 
2174+         self . visit_id ( id) ; 
2175+         for  attr in  attrs. iter_mut ( )  { 
2176+             self . visit_attribute ( attr) ; 
2177+         } 
2178+         self . visit_pat ( pat) ; 
2179+         if  let  Some ( ty)  = ty { 
2180+             self . visit_ty ( ty) ; 
2181+         } 
2182+         match  kind { 
2183+             ast:: LocalKind :: Decl  => { } 
2184+             ast:: LocalKind :: Init ( init)  => { 
2185+                 self . visit_expr ( init) ; 
2186+             } 
2187+             ast:: LocalKind :: InitElse ( init,  els)  => { 
2188+                 self . expr_under_let_init_else  = true ; 
2189+                 self . visit_expr ( init) ; 
2190+                 self . expr_under_let_init_else  = false ; 
2191+                 self . visit_block ( els) ; 
2192+             } 
2193+         } 
2194+         visit_lazy_tts ( self ,  tokens) ; 
2195+         if  let  Some ( sp)  = colon_sp { 
2196+             self . visit_span ( sp) ; 
2197+         } 
2198+         self . visit_span ( span) ; 
2199+     } 
2200+ 
21702201    fn  visit_crate ( & mut  self ,  node :  & mut  ast:: Crate )  { 
21712202        self . visit_node ( node) 
21722203    } 
@@ -2180,6 +2211,13 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
21802211    } 
21812212
21822213    fn  visit_expr ( & mut  self ,  node :  & mut  P < ast:: Expr > )  { 
2214+         if  self . expr_under_let_init_else 
2215+             && let  ast:: ExprKind :: Paren ( paren)  = & node. kind 
2216+             && let  ast:: ExprKind :: MacCall ( mac)  = & paren. kind 
2217+             && mac. args . delim  == Delimiter :: Brace 
2218+         { 
2219+             self . cx . resolver . add_necessary_parens ( node. span ) ; 
2220+         } 
21832221        // FIXME: Feature gating is performed inconsistently between `Expr` and `OptExpr`. 
21842222        if  let  Some ( attr)  = node. attrs . first ( )  { 
21852223            self . cfg ( ) . maybe_emit_expr_attr_err ( attr) ; 
0 commit comments