@@ -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,22 @@ 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 mac = match expr_to_spanned_string ( ecx, template_expr, msg) {
470+ ExpandResult :: Ready ( ret) => ret,
471+ ExpandResult :: Retry ( _) => return ExpandResult :: Retry ( ( ) ) ,
472+ } ;
473+ match mac {
470474 Ok ( template_part) => template_part,
471475 Err ( err) => {
472- return Err ( match err {
476+ let err = Err ( match err {
473477 Ok ( ( err, _) ) => err. emit ( ) ,
474478 Err ( guar) => guar,
475479 } ) ;
480+ return ExpandResult :: Ready ( err) ;
476481 }
477- } ;
482+ }
483+ } ;
478484
479485 let str_style = match template_style {
480486 ast:: StrStyle :: Cooked => None ,
@@ -562,7 +568,7 @@ fn expand_preparsed_asm(
562568 e. span_label ( err_sp, label) ;
563569 }
564570 let guar = e. emit ( ) ;
565- return Err ( guar) ;
571+ return ExpandResult :: Ready ( Err ( guar) ) ;
566572 }
567573
568574 curarg = parser. curarg ;
@@ -729,24 +735,28 @@ fn expand_preparsed_asm(
729735 }
730736 }
731737
732- Ok ( ast:: InlineAsm {
738+ ExpandResult :: Ready ( Ok ( ast:: InlineAsm {
733739 template,
734740 template_strs : template_strs. into_boxed_slice ( ) ,
735741 operands : args. operands ,
736742 clobber_abis : args. clobber_abis ,
737743 options : args. options ,
738744 line_spans,
739- } )
745+ } ) )
740746}
741747
742748pub ( super ) fn expand_asm < ' cx > (
743749 ecx : & ' cx mut ExtCtxt < ' _ > ,
744750 sp : Span ,
745751 tts : TokenStream ,
746- ) -> Box < dyn base :: MacResult + ' cx > {
747- match parse_args ( ecx, sp, tts, false ) {
752+ ) -> MacroExpanderResult < ' cx > {
753+ let res = match parse_args ( ecx, sp, tts, false ) {
748754 Ok ( args) => {
749- let expr = match expand_preparsed_asm ( ecx, args) {
755+ let mac = match expand_preparsed_asm ( ecx, args) {
756+ ExpandResult :: Ready ( ret) => ret,
757+ ExpandResult :: Retry ( _) => return ExpandResult :: Retry ( ( ) ) ,
758+ } ;
759+ let expr = match mac {
750760 Ok ( inline_asm) => P ( ast:: Expr {
751761 id : ast:: DUMMY_NODE_ID ,
752762 kind : ast:: ExprKind :: InlineAsm ( P ( inline_asm) ) ,
@@ -762,34 +772,42 @@ pub(super) fn expand_asm<'cx>(
762772 let guar = err. emit ( ) ;
763773 DummyResult :: any ( sp, guar)
764774 }
765- }
775+ } ;
776+ ExpandResult :: Ready ( res)
766777}
767778
768779pub ( super ) fn expand_global_asm < ' cx > (
769780 ecx : & ' cx mut ExtCtxt < ' _ > ,
770781 sp : Span ,
771782 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 ,
783+ ) -> MacroExpanderResult < ' cx > {
784+ let res = match parse_args ( ecx, sp, tts, true ) {
785+ Ok ( args) => {
786+ let mac = match expand_preparsed_asm ( ecx, args) {
787+ ExpandResult :: Ready ( ret) => ret,
788+ ExpandResult :: Retry ( _) => return ExpandResult :: Retry ( ( ) ) ,
789+ } ;
790+ match mac {
791+ Ok ( inline_asm) => MacEager :: items ( smallvec ! [ P ( ast:: Item {
792+ ident: Ident :: empty( ) ,
793+ attrs: ast:: AttrVec :: new( ) ,
794+ id: ast:: DUMMY_NODE_ID ,
795+ kind: ast:: ItemKind :: GlobalAsm ( Box :: new( inline_asm) ) ,
796+ vis: ast:: Visibility {
797+ span: sp. shrink_to_lo( ) ,
798+ kind: ast:: VisibilityKind :: Inherited ,
799+ tokens: None ,
800+ } ,
801+ span: sp,
783802 tokens: None ,
784- } ,
785- span: sp,
786- tokens: None ,
787- } ) ] ) ,
788- Err ( guar) => DummyResult :: any ( sp, guar) ,
789- } ,
803+ } ) ] ) ,
804+ Err ( guar) => DummyResult :: any ( sp, guar) ,
805+ }
806+ }
790807 Err ( err) => {
791808 let guar = err. emit ( ) ;
792809 DummyResult :: any ( sp, guar)
793810 }
794- }
811+ } ;
812+ ExpandResult :: Ready ( res)
795813}
0 commit comments