@@ -13,7 +13,7 @@ use rustc_session::lint;
1313use  rustc_session:: parse:: ParseSess ; 
1414use  rustc_span:: symbol:: Ident ; 
1515use  rustc_span:: symbol:: { kw,  sym,  Symbol } ; 
16- use  rustc_span:: { InnerSpan ,  Span } ; 
16+ use  rustc_span:: { ErrorGuaranteed ,   InnerSpan ,  Span } ; 
1717use  rustc_target:: asm:: InlineAsmArch ; 
1818use  smallvec:: smallvec; 
1919
@@ -433,7 +433,10 @@ fn parse_reg<'a>(
433433    Ok ( result) 
434434} 
435435
436- fn  expand_preparsed_asm ( ecx :  & mut  ExtCtxt < ' _ > ,  args :  AsmArgs )  -> Option < ast:: InlineAsm >  { 
436+ fn  expand_preparsed_asm ( 
437+     ecx :  & mut  ExtCtxt < ' _ > , 
438+     args :  AsmArgs , 
439+ )  -> Result < ast:: InlineAsm ,  ErrorGuaranteed >  { 
437440    let  mut  template = vec ! [ ] ; 
438441    // Register operands are implicitly used since they are not allowed to be 
439442    // referenced in the template string. 
@@ -459,10 +462,10 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
459462            match  expr_to_spanned_string ( ecx,  template_expr,  msg)  { 
460463                Ok ( template_part)  => template_part, 
461464                Err ( err)  => { 
462-                     if   let   Some ( ( err ,  _ ) )  =  err { 
463-                         err. emit ( ) ; 
464-                     } 
465-                     return   None ; 
465+                     return   Err ( match  err { 
466+                         Ok ( ( err,  _ ) )  => err . emit ( ) , 
467+                          Err ( guar )  => guar , 
468+                     } ) ; 
466469                } 
467470            } ; 
468471
@@ -551,8 +554,8 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
551554                let  err_sp = template_span. from_inner ( InnerSpan :: new ( span. start ,  span. end ) ) ; 
552555                e. span_label ( err_sp,  label) ; 
553556            } 
554-             e. emit ( ) ; 
555-             return  None ; 
557+             let  guar =  e. emit ( ) ; 
558+             return  Err ( guar ) ; 
556559        } 
557560
558561        curarg = parser. curarg ; 
@@ -719,7 +722,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
719722        } 
720723    } 
721724
722-     Some ( ast:: InlineAsm  { 
725+     Ok ( ast:: InlineAsm  { 
723726        template, 
724727        template_strs :  template_strs. into_boxed_slice ( ) , 
725728        operands :  args. operands , 
@@ -736,22 +739,21 @@ pub(super) fn expand_asm<'cx>(
736739)  -> Box < dyn  base:: MacResult  + ' cx >  { 
737740    match  parse_args ( ecx,  sp,  tts,  false )  { 
738741        Ok ( args)  => { 
739-             let  expr = if   let   Some ( inline_asm )  =  expand_preparsed_asm ( ecx,  args)  { 
740-                 P ( ast:: Expr  { 
742+             let  expr = match  expand_preparsed_asm ( ecx,  args)  { 
743+                 Ok ( inline_asm )  =>  P ( ast:: Expr  { 
741744                    id :  ast:: DUMMY_NODE_ID , 
742745                    kind :  ast:: ExprKind :: InlineAsm ( P ( inline_asm) ) , 
743746                    span :  sp, 
744747                    attrs :  ast:: AttrVec :: new ( ) , 
745748                    tokens :  None , 
746-                 } ) 
747-             }  else  { 
748-                 DummyResult :: raw_expr ( sp,  true ) 
749+                 } ) , 
750+                 Err ( guar)  => DummyResult :: raw_expr ( sp,  Some ( guar) ) , 
749751            } ; 
750752            MacEager :: expr ( expr) 
751753        } 
752754        Err ( err)  => { 
753-             err. emit ( ) ; 
754-             DummyResult :: any ( sp) 
755+             let  guar =  err. emit ( ) ; 
756+             DummyResult :: any ( sp,  guar ) 
755757        } 
756758    } 
757759} 
@@ -762,28 +764,25 @@ pub(super) fn expand_global_asm<'cx>(
762764    tts :  TokenStream , 
763765)  -> Box < dyn  base:: MacResult  + ' cx >  { 
764766    match  parse_args ( ecx,  sp,  tts,  true )  { 
765-         Ok ( args)  => { 
766-             if  let  Some ( inline_asm)  = expand_preparsed_asm ( ecx,  args)  { 
767-                 MacEager :: items ( smallvec ! [ P ( ast:: Item  { 
768-                     ident:  Ident :: empty( ) , 
769-                     attrs:  ast:: AttrVec :: new( ) , 
770-                     id:  ast:: DUMMY_NODE_ID , 
771-                     kind:  ast:: ItemKind :: GlobalAsm ( Box :: new( inline_asm) ) , 
772-                     vis:  ast:: Visibility  { 
773-                         span:  sp. shrink_to_lo( ) , 
774-                         kind:  ast:: VisibilityKind :: Inherited , 
775-                         tokens:  None , 
776-                     } , 
777-                     span:  sp, 
767+         Ok ( args)  => match  expand_preparsed_asm ( ecx,  args)  { 
768+             Ok ( inline_asm)  => MacEager :: items ( smallvec ! [ P ( ast:: Item  { 
769+                 ident:  Ident :: empty( ) , 
770+                 attrs:  ast:: AttrVec :: new( ) , 
771+                 id:  ast:: DUMMY_NODE_ID , 
772+                 kind:  ast:: ItemKind :: GlobalAsm ( Box :: new( inline_asm) ) , 
773+                 vis:  ast:: Visibility  { 
774+                     span:  sp. shrink_to_lo( ) , 
775+                     kind:  ast:: VisibilityKind :: Inherited , 
778776                    tokens:  None , 
779-                 } ) ] ) 
780-             }  else  { 
781-                 DummyResult :: any ( sp) 
782-             } 
783-         } 
777+                 } , 
778+                 span:  sp, 
779+                 tokens:  None , 
780+             } ) ] ) , 
781+             Err ( guar)  => DummyResult :: any ( sp,  guar) , 
782+         } , 
784783        Err ( err)  => { 
785-             err. emit ( ) ; 
786-             DummyResult :: any ( sp) 
784+             let  guar =  err. emit ( ) ; 
785+             DummyResult :: any ( sp,  guar ) 
787786        } 
788787    } 
789788} 
0 commit comments