@@ -13,7 +13,7 @@ use rustc_session::lint;
13
13
use rustc_session:: parse:: ParseSess ;
14
14
use rustc_span:: symbol:: Ident ;
15
15
use rustc_span:: symbol:: { kw, sym, Symbol } ;
16
- use rustc_span:: { InnerSpan , Span } ;
16
+ use rustc_span:: { ErrorGuaranteed , InnerSpan , Span } ;
17
17
use rustc_target:: asm:: InlineAsmArch ;
18
18
use smallvec:: smallvec;
19
19
@@ -433,7 +433,10 @@ fn parse_reg<'a>(
433
433
Ok ( result)
434
434
}
435
435
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 > {
437
440
let mut template = vec ! [ ] ;
438
441
// Register operands are implicitly used since they are not allowed to be
439
442
// referenced in the template string.
@@ -459,10 +462,10 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
459
462
match expr_to_spanned_string ( ecx, template_expr, msg) {
460
463
Ok ( template_part) => template_part,
461
464
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
+ } ) ;
466
469
}
467
470
} ;
468
471
@@ -551,8 +554,8 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
551
554
let err_sp = template_span. from_inner ( InnerSpan :: new ( span. start , span. end ) ) ;
552
555
e. span_label ( err_sp, label) ;
553
556
}
554
- e. emit ( ) ;
555
- return None ;
557
+ let guar = e. emit ( ) ;
558
+ return Err ( guar ) ;
556
559
}
557
560
558
561
curarg = parser. curarg ;
@@ -719,7 +722,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
719
722
}
720
723
}
721
724
722
- Some ( ast:: InlineAsm {
725
+ Ok ( ast:: InlineAsm {
723
726
template,
724
727
template_strs : template_strs. into_boxed_slice ( ) ,
725
728
operands : args. operands ,
@@ -736,22 +739,21 @@ pub(super) fn expand_asm<'cx>(
736
739
) -> Box < dyn base:: MacResult + ' cx > {
737
740
match parse_args ( ecx, sp, tts, false ) {
738
741
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 {
741
744
id : ast:: DUMMY_NODE_ID ,
742
745
kind : ast:: ExprKind :: InlineAsm ( P ( inline_asm) ) ,
743
746
span : sp,
744
747
attrs : ast:: AttrVec :: new ( ) ,
745
748
tokens : None ,
746
- } )
747
- } else {
748
- DummyResult :: raw_expr ( sp, true )
749
+ } ) ,
750
+ Err ( guar) => DummyResult :: raw_expr ( sp, Some ( guar) ) ,
749
751
} ;
750
752
MacEager :: expr ( expr)
751
753
}
752
754
Err ( err) => {
753
- err. emit ( ) ;
754
- DummyResult :: any ( sp)
755
+ let guar = err. emit ( ) ;
756
+ DummyResult :: any ( sp, guar )
755
757
}
756
758
}
757
759
}
@@ -762,28 +764,25 @@ pub(super) fn expand_global_asm<'cx>(
762
764
tts : TokenStream ,
763
765
) -> Box < dyn base:: MacResult + ' cx > {
764
766
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 ,
778
776
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
+ } ,
784
783
Err ( err) => {
785
- err. emit ( ) ;
786
- DummyResult :: any ( sp)
784
+ let guar = err. emit ( ) ;
785
+ DummyResult :: any ( sp, guar )
787
786
}
788
787
}
789
788
}
0 commit comments