@@ -5,7 +5,7 @@ use rustc_ast::token::{self, Delimiter};
5
5
use rustc_ast:: tokenstream:: TokenStream ;
6
6
use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap } ;
7
7
use rustc_errors:: PResult ;
8
- use rustc_expand:: base:: { self , * } ;
8
+ use rustc_expand:: base:: * ;
9
9
use rustc_index:: bit_set:: GrowableBitSet ;
10
10
use rustc_parse:: parser:: Parser ;
11
11
use rustc_parse_format as parse;
@@ -443,7 +443,7 @@ fn parse_reg<'a>(
443
443
fn expand_preparsed_asm (
444
444
ecx : & mut ExtCtxt < ' _ > ,
445
445
args : AsmArgs ,
446
- ) -> Result < ast:: InlineAsm , ErrorGuaranteed > {
446
+ ) -> ExpandResult < Result < ast:: InlineAsm , ErrorGuaranteed > , ( ) > {
447
447
let mut template = vec ! [ ] ;
448
448
// Register operands are implicitly used since they are not allowed to be
449
449
// referenced in the template string.
@@ -465,16 +465,22 @@ fn expand_preparsed_asm(
465
465
466
466
let msg = "asm template must be a string literal" ;
467
467
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 {
470
474
Ok ( template_part) => template_part,
471
475
Err ( err) => {
472
- return Err ( match err {
476
+ let err = Err ( match err {
473
477
Ok ( ( err, _) ) => err. emit ( ) ,
474
478
Err ( guar) => guar,
475
479
} ) ;
480
+ return ExpandResult :: Ready ( err) ;
476
481
}
477
- } ;
482
+ }
483
+ } ;
478
484
479
485
let str_style = match template_style {
480
486
ast:: StrStyle :: Cooked => None ,
@@ -562,7 +568,7 @@ fn expand_preparsed_asm(
562
568
e. span_label ( err_sp, label) ;
563
569
}
564
570
let guar = e. emit ( ) ;
565
- return Err ( guar) ;
571
+ return ExpandResult :: Ready ( Err ( guar) ) ;
566
572
}
567
573
568
574
curarg = parser. curarg ;
@@ -729,24 +735,28 @@ fn expand_preparsed_asm(
729
735
}
730
736
}
731
737
732
- Ok ( ast:: InlineAsm {
738
+ ExpandResult :: Ready ( Ok ( ast:: InlineAsm {
733
739
template,
734
740
template_strs : template_strs. into_boxed_slice ( ) ,
735
741
operands : args. operands ,
736
742
clobber_abis : args. clobber_abis ,
737
743
options : args. options ,
738
744
line_spans,
739
- } )
745
+ } ) )
740
746
}
741
747
742
748
pub ( super ) fn expand_asm < ' cx > (
743
749
ecx : & ' cx mut ExtCtxt < ' _ > ,
744
750
sp : Span ,
745
751
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 ) {
748
754
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 {
750
760
Ok ( inline_asm) => P ( ast:: Expr {
751
761
id : ast:: DUMMY_NODE_ID ,
752
762
kind : ast:: ExprKind :: InlineAsm ( P ( inline_asm) ) ,
@@ -762,34 +772,42 @@ pub(super) fn expand_asm<'cx>(
762
772
let guar = err. emit ( ) ;
763
773
DummyResult :: any ( sp, guar)
764
774
}
765
- }
775
+ } ;
776
+ ExpandResult :: Ready ( res)
766
777
}
767
778
768
779
pub ( super ) fn expand_global_asm < ' cx > (
769
780
ecx : & ' cx mut ExtCtxt < ' _ > ,
770
781
sp : Span ,
771
782
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,
783
802
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
+ }
790
807
Err ( err) => {
791
808
let guar = err. emit ( ) ;
792
809
DummyResult :: any ( sp, guar)
793
810
}
794
- }
811
+ } ;
812
+ ExpandResult :: Ready ( res)
795
813
}
0 commit comments