@@ -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,20 @@ 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 ExpandResult :: Ready ( mac) = expr_to_spanned_string ( ecx, template_expr, msg) else {
470
+ return ExpandResult :: Retry ( ( ) ) ;
471
+ } ;
472
+ match mac {
470
473
Ok ( template_part) => template_part,
471
474
Err ( err) => {
472
- return Err ( match err {
475
+ return ExpandResult :: Ready ( Err ( match err {
473
476
Ok ( ( err, _) ) => err. emit ( ) ,
474
477
Err ( guar) => guar,
475
- } ) ;
478
+ } ) ) ;
476
479
}
477
- } ;
480
+ }
481
+ } ;
478
482
479
483
let str_style = match template_style {
480
484
ast:: StrStyle :: Cooked => None ,
@@ -562,7 +566,7 @@ fn expand_preparsed_asm(
562
566
e. span_label ( err_sp, label) ;
563
567
}
564
568
let guar = e. emit ( ) ;
565
- return Err ( guar) ;
569
+ return ExpandResult :: Ready ( Err ( guar) ) ;
566
570
}
567
571
568
572
curarg = parser. curarg ;
@@ -729,24 +733,27 @@ fn expand_preparsed_asm(
729
733
}
730
734
}
731
735
732
- Ok ( ast:: InlineAsm {
736
+ ExpandResult :: Ready ( Ok ( ast:: InlineAsm {
733
737
template,
734
738
template_strs : template_strs. into_boxed_slice ( ) ,
735
739
operands : args. operands ,
736
740
clobber_abis : args. clobber_abis ,
737
741
options : args. options ,
738
742
line_spans,
739
- } )
743
+ } ) )
740
744
}
741
745
742
746
pub ( super ) fn expand_asm < ' cx > (
743
747
ecx : & ' cx mut ExtCtxt < ' _ > ,
744
748
sp : Span ,
745
749
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 ) {
748
752
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 {
750
757
Ok ( inline_asm) => P ( ast:: Expr {
751
758
id : ast:: DUMMY_NODE_ID ,
752
759
kind : ast:: ExprKind :: InlineAsm ( P ( inline_asm) ) ,
@@ -762,34 +769,39 @@ pub(super) fn expand_asm<'cx>(
762
769
let guar = err. emit ( ) ;
763
770
DummyResult :: any ( sp, guar)
764
771
}
765
- }
772
+ } )
766
773
}
767
774
768
775
pub ( super ) fn expand_global_asm < ' cx > (
769
776
ecx : & ' cx mut ExtCtxt < ' _ > ,
770
777
sp : Span ,
771
778
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,
783
797
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
+ }
790
802
Err ( err) => {
791
803
let guar = err. emit ( ) ;
792
804
DummyResult :: any ( sp, guar)
793
805
}
794
- }
806
+ } )
795
807
}
0 commit comments