@@ -5,7 +5,7 @@ use rustc_ast::token::{self, Delimiter};
55use rustc_ast:: tokenstream:: TokenStream ;
66use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap } ;
77use rustc_errors:: PResult ;
8- use rustc_expand:: base:: { self , * } ;
8+ use rustc_expand:: base:: * ;
99use rustc_index:: bit_set:: GrowableBitSet ;
1010use rustc_parse:: parser:: Parser ;
1111use rustc_parse_format as parse;
@@ -443,7 +443,7 @@ fn parse_reg<'a>(
443443fn expand_preparsed_asm (
444444 ecx : & mut ExtCtxt < ' _ > ,
445445 args : AsmArgs ,
446- ) -> Result < ast:: InlineAsm , ErrorGuaranteed > {
446+ ) -> ExpandResult < Result < ast:: InlineAsm , ErrorGuaranteed > , ( ) > {
447447 let mut template = vec ! [ ] ;
448448 // Register operands are implicitly used since they are not allowed to be
449449 // referenced in the template string.
@@ -465,16 +465,20 @@ fn expand_preparsed_asm(
465465
466466 let msg = "asm template must be a string literal" ;
467467 let template_sp = template_expr. span ;
468- let ( template_str, template_style, template_span) =
469- match expr_to_spanned_string ( ecx, template_expr, msg) {
468+ let ( template_str, template_style, template_span) = {
469+ let ExpandResult :: Ready ( mac) = expr_to_spanned_string ( ecx, template_expr, msg) else {
470+ return ExpandResult :: Retry ( ( ) ) ;
471+ } ;
472+ match mac {
470473 Ok ( template_part) => template_part,
471474 Err ( err) => {
472- return Err ( match err {
475+ return ExpandResult :: Ready ( Err ( match err {
473476 Ok ( ( err, _) ) => err. emit ( ) ,
474477 Err ( guar) => guar,
475- } ) ;
478+ } ) ) ;
476479 }
477- } ;
480+ }
481+ } ;
478482
479483 let str_style = match template_style {
480484 ast:: StrStyle :: Cooked => None ,
@@ -562,7 +566,7 @@ fn expand_preparsed_asm(
562566 e. span_label ( err_sp, label) ;
563567 }
564568 let guar = e. emit ( ) ;
565- return Err ( guar) ;
569+ return ExpandResult :: Ready ( Err ( guar) ) ;
566570 }
567571
568572 curarg = parser. curarg ;
@@ -729,24 +733,27 @@ fn expand_preparsed_asm(
729733 }
730734 }
731735
732- Ok ( ast:: InlineAsm {
736+ ExpandResult :: Ready ( Ok ( ast:: InlineAsm {
733737 template,
734738 template_strs : template_strs. into_boxed_slice ( ) ,
735739 operands : args. operands ,
736740 clobber_abis : args. clobber_abis ,
737741 options : args. options ,
738742 line_spans,
739- } )
743+ } ) )
740744}
741745
742746pub ( super ) fn expand_asm < ' cx > (
743747 ecx : & ' cx mut ExtCtxt < ' _ > ,
744748 sp : Span ,
745749 tts : TokenStream ,
746- ) -> Box < dyn base :: MacResult + ' cx > {
747- match parse_args ( ecx, sp, tts, false ) {
750+ ) -> MacroExpanderResult < ' cx > {
751+ ExpandResult :: Ready ( match parse_args ( ecx, sp, tts, false ) {
748752 Ok ( args) => {
749- let expr = match expand_preparsed_asm ( ecx, args) {
753+ let ExpandResult :: Ready ( mac) = expand_preparsed_asm ( ecx, args) else {
754+ return ExpandResult :: Retry ( ( ) ) ;
755+ } ;
756+ let expr = match mac {
750757 Ok ( inline_asm) => P ( ast:: Expr {
751758 id : ast:: DUMMY_NODE_ID ,
752759 kind : ast:: ExprKind :: InlineAsm ( P ( inline_asm) ) ,
@@ -762,34 +769,39 @@ pub(super) fn expand_asm<'cx>(
762769 let guar = err. emit ( ) ;
763770 DummyResult :: any ( sp, guar)
764771 }
765- }
772+ } )
766773}
767774
768775pub ( super ) fn expand_global_asm < ' cx > (
769776 ecx : & ' cx mut ExtCtxt < ' _ > ,
770777 sp : Span ,
771778 tts : TokenStream ,
772- ) -> Box < dyn base:: MacResult + ' cx > {
773- match parse_args ( ecx, sp, tts, true ) {
774- Ok ( args) => match expand_preparsed_asm ( ecx, args) {
775- Ok ( inline_asm) => MacEager :: items ( smallvec ! [ P ( ast:: Item {
776- ident: Ident :: empty( ) ,
777- attrs: ast:: AttrVec :: new( ) ,
778- id: ast:: DUMMY_NODE_ID ,
779- kind: ast:: ItemKind :: GlobalAsm ( Box :: new( inline_asm) ) ,
780- vis: ast:: Visibility {
781- span: sp. shrink_to_lo( ) ,
782- kind: ast:: VisibilityKind :: Inherited ,
779+ ) -> MacroExpanderResult < ' cx > {
780+ ExpandResult :: Ready ( match parse_args ( ecx, sp, tts, true ) {
781+ Ok ( args) => {
782+ let ExpandResult :: Ready ( mac) = expand_preparsed_asm ( ecx, args) else {
783+ return ExpandResult :: Retry ( ( ) ) ;
784+ } ;
785+ match mac {
786+ Ok ( inline_asm) => MacEager :: items ( smallvec ! [ P ( ast:: Item {
787+ ident: Ident :: empty( ) ,
788+ attrs: ast:: AttrVec :: new( ) ,
789+ id: ast:: DUMMY_NODE_ID ,
790+ kind: ast:: ItemKind :: GlobalAsm ( Box :: new( inline_asm) ) ,
791+ vis: ast:: Visibility {
792+ span: sp. shrink_to_lo( ) ,
793+ kind: ast:: VisibilityKind :: Inherited ,
794+ tokens: None ,
795+ } ,
796+ span: sp,
783797 tokens: None ,
784- } ,
785- span: sp,
786- tokens: None ,
787- } ) ] ) ,
788- Err ( guar) => DummyResult :: any ( sp, guar) ,
789- } ,
798+ } ) ] ) ,
799+ Err ( guar) => DummyResult :: any ( sp, guar) ,
800+ }
801+ }
790802 Err ( err) => {
791803 let guar = err. emit ( ) ;
792804 DummyResult :: any ( sp, guar)
793805 }
794- }
806+ } )
795807}
0 commit comments