@@ -8,9 +8,10 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
88use rustc_errors:: PResult ;
99use rustc_expand:: base:: * ;
1010use rustc_index:: bit_set:: GrowableBitSet ;
11- use rustc_parse:: parser:: Parser ;
11+ use rustc_parse:: exp;
12+ use rustc_parse:: parser:: { Parser , TokenType } ;
1213use rustc_session:: lint;
13- use rustc_span:: symbol:: { Ident , Symbol , kw, sym } ;
14+ use rustc_span:: symbol:: { Ident , Symbol , kw} ;
1415use rustc_span:: { ErrorGuaranteed , InnerSpan , Span } ;
1516use rustc_target:: asm:: InlineAsmArch ;
1617use smallvec:: smallvec;
@@ -39,11 +40,11 @@ pub struct AsmArgs {
3940/// - `Err(_)` if the current token matches the keyword, but was not expected
4041fn eat_operand_keyword < ' a > (
4142 p : & mut Parser < ' a > ,
42- symbol : Symbol ,
43+ ( symbol, token_type ) : ( Symbol , TokenType ) ,
4344 asm_macro : AsmMacro ,
4445) -> PResult < ' a , bool > {
4546 if matches ! ( asm_macro, AsmMacro :: Asm ) {
46- Ok ( p. eat_keyword ( symbol) )
47+ Ok ( p. eat_keyword ( ( symbol, token_type ) ) )
4748 } else {
4849 let span = p. token . span ;
4950 if p. eat_keyword_noexpect ( symbol) {
@@ -96,28 +97,28 @@ pub fn parse_asm_args<'a>(
9697
9798 let mut allow_templates = true ;
9899 while p. token != token:: Eof {
99- if !p. eat ( & token :: Comma ) {
100+ if !p. eat ( exp ! ( Comma ) ) {
100101 if allow_templates {
101102 // After a template string, we always expect *only* a comma...
102103 return Err ( dcx. create_err ( errors:: AsmExpectedComma { span : p. token . span } ) ) ;
103104 } else {
104105 // ...after that delegate to `expect` to also include the other expected tokens.
105- return Err ( p. expect ( & token :: Comma ) . err ( ) . unwrap ( ) ) ;
106+ return Err ( p. expect ( exp ! ( Comma ) ) . err ( ) . unwrap ( ) ) ;
106107 }
107108 }
108109 if p. token == token:: Eof {
109110 break ;
110111 } // accept trailing commas
111112
112113 // Parse clobber_abi
113- if p. eat_keyword ( sym :: clobber_abi ) {
114+ if p. eat_keyword ( exp ! ( ClobberAbi ) ) {
114115 parse_clobber_abi ( p, & mut args) ?;
115116 allow_templates = false ;
116117 continue ;
117118 }
118119
119120 // Parse options
120- if p. eat_keyword ( sym :: options ) {
121+ if p. eat_keyword ( exp ! ( Options ) ) {
121122 parse_options ( p, & mut args, asm_macro) ?;
122123 allow_templates = false ;
123124 continue ;
@@ -129,65 +130,65 @@ pub fn parse_asm_args<'a>(
129130 let name = if p. token . is_ident ( ) && p. look_ahead ( 1 , |t| * t == token:: Eq ) {
130131 let ( ident, _) = p. token . ident ( ) . unwrap ( ) ;
131132 p. bump ( ) ;
132- p. expect ( & token :: Eq ) ?;
133+ p. expect ( exp ! ( Eq ) ) ?;
133134 allow_templates = false ;
134135 Some ( ident. name )
135136 } else {
136137 None
137138 } ;
138139
139140 let mut explicit_reg = false ;
140- let op = if eat_operand_keyword ( p, kw :: In , asm_macro) ? {
141+ let op = if eat_operand_keyword ( p, exp ! ( In ) , asm_macro) ? {
141142 let reg = parse_reg ( p, & mut explicit_reg) ?;
142- if p. eat_keyword ( kw :: Underscore ) {
143+ if p. eat_keyword ( exp ! ( Underscore ) ) {
143144 let err = dcx. create_err ( errors:: AsmUnderscoreInput { span : p. token . span } ) ;
144145 return Err ( err) ;
145146 }
146147 let expr = p. parse_expr ( ) ?;
147148 ast:: InlineAsmOperand :: In { reg, expr }
148- } else if eat_operand_keyword ( p, sym :: out , asm_macro) ? {
149+ } else if eat_operand_keyword ( p, exp ! ( Out ) , asm_macro) ? {
149150 let reg = parse_reg ( p, & mut explicit_reg) ?;
150- let expr = if p. eat_keyword ( kw :: Underscore ) { None } else { Some ( p. parse_expr ( ) ?) } ;
151+ let expr = if p. eat_keyword ( exp ! ( Underscore ) ) { None } else { Some ( p. parse_expr ( ) ?) } ;
151152 ast:: InlineAsmOperand :: Out { reg, expr, late : false }
152- } else if eat_operand_keyword ( p, sym :: lateout , asm_macro) ? {
153+ } else if eat_operand_keyword ( p, exp ! ( Lateout ) , asm_macro) ? {
153154 let reg = parse_reg ( p, & mut explicit_reg) ?;
154- let expr = if p. eat_keyword ( kw :: Underscore ) { None } else { Some ( p. parse_expr ( ) ?) } ;
155+ let expr = if p. eat_keyword ( exp ! ( Underscore ) ) { None } else { Some ( p. parse_expr ( ) ?) } ;
155156 ast:: InlineAsmOperand :: Out { reg, expr, late : true }
156- } else if eat_operand_keyword ( p, sym :: inout , asm_macro) ? {
157+ } else if eat_operand_keyword ( p, exp ! ( Inout ) , asm_macro) ? {
157158 let reg = parse_reg ( p, & mut explicit_reg) ?;
158- if p. eat_keyword ( kw :: Underscore ) {
159+ if p. eat_keyword ( exp ! ( Underscore ) ) {
159160 let err = dcx. create_err ( errors:: AsmUnderscoreInput { span : p. token . span } ) ;
160161 return Err ( err) ;
161162 }
162163 let expr = p. parse_expr ( ) ?;
163- if p. eat ( & token :: FatArrow ) {
164+ if p. eat ( exp ! ( FatArrow ) ) {
164165 let out_expr =
165- if p. eat_keyword ( kw :: Underscore ) { None } else { Some ( p. parse_expr ( ) ?) } ;
166+ if p. eat_keyword ( exp ! ( Underscore ) ) { None } else { Some ( p. parse_expr ( ) ?) } ;
166167 ast:: InlineAsmOperand :: SplitInOut { reg, in_expr : expr, out_expr, late : false }
167168 } else {
168169 ast:: InlineAsmOperand :: InOut { reg, expr, late : false }
169170 }
170- } else if eat_operand_keyword ( p, sym :: inlateout , asm_macro) ? {
171+ } else if eat_operand_keyword ( p, exp ! ( Inlateout ) , asm_macro) ? {
171172 let reg = parse_reg ( p, & mut explicit_reg) ?;
172- if p. eat_keyword ( kw :: Underscore ) {
173+ if p. eat_keyword ( exp ! ( Underscore ) ) {
173174 let err = dcx. create_err ( errors:: AsmUnderscoreInput { span : p. token . span } ) ;
174175 return Err ( err) ;
175176 }
176177 let expr = p. parse_expr ( ) ?;
177- if p. eat ( & token :: FatArrow ) {
178+ if p. eat ( exp ! ( FatArrow ) ) {
178179 let out_expr =
179- if p. eat_keyword ( kw :: Underscore ) { None } else { Some ( p. parse_expr ( ) ?) } ;
180+ if p. eat_keyword ( exp ! ( Underscore ) ) { None } else { Some ( p. parse_expr ( ) ?) } ;
180181 ast:: InlineAsmOperand :: SplitInOut { reg, in_expr : expr, out_expr, late : true }
181182 } else {
182183 ast:: InlineAsmOperand :: InOut { reg, expr, late : true }
183184 }
184- } else if eat_operand_keyword ( p, sym :: label , asm_macro) ? {
185+ } else if eat_operand_keyword ( p, exp ! ( Label ) , asm_macro) ? {
185186 let block = p. parse_block ( ) ?;
186187 ast:: InlineAsmOperand :: Label { block }
187- } else if p. eat_keyword ( kw :: Const ) {
188+ } else if p. eat_keyword ( exp ! ( Const ) ) {
188189 let anon_const = p. parse_expr_anon_const ( ) ?;
189190 ast:: InlineAsmOperand :: Const { anon_const }
190- } else if p. eat_keyword ( sym :: sym ) {
191+ } else if p. eat_keyword ( exp ! ( Sym ) ) {
191192 let expr = p. parse_expr ( ) ?;
192193 let ast:: ExprKind :: Path ( qself, path) = & expr. kind else {
193194 let err = dcx. create_err ( errors:: AsmSymNoPath { span : expr. span } ) ;
@@ -390,31 +391,32 @@ fn parse_options<'a>(
390391) -> PResult < ' a , ( ) > {
391392 let span_start = p. prev_token . span ;
392393
393- p. expect ( & token:: OpenDelim ( Delimiter :: Parenthesis ) ) ?;
394-
395- while !p. eat ( & token:: CloseDelim ( Delimiter :: Parenthesis ) ) {
396- const OPTIONS : [ ( Symbol , ast:: InlineAsmOptions ) ; ast:: InlineAsmOptions :: COUNT ] = [
397- ( sym:: pure, ast:: InlineAsmOptions :: PURE ) ,
398- ( sym:: nomem, ast:: InlineAsmOptions :: NOMEM ) ,
399- ( sym:: readonly, ast:: InlineAsmOptions :: READONLY ) ,
400- ( sym:: preserves_flags, ast:: InlineAsmOptions :: PRESERVES_FLAGS ) ,
401- ( sym:: noreturn, ast:: InlineAsmOptions :: NORETURN ) ,
402- ( sym:: nostack, ast:: InlineAsmOptions :: NOSTACK ) ,
403- ( sym:: may_unwind, ast:: InlineAsmOptions :: MAY_UNWIND ) ,
404- ( sym:: att_syntax, ast:: InlineAsmOptions :: ATT_SYNTAX ) ,
405- ( kw:: Raw , ast:: InlineAsmOptions :: RAW ) ,
394+ p. expect ( exp ! ( OpenParen ) ) ?;
395+
396+ while !p. eat ( exp ! ( CloseParen ) ) {
397+ const OPTIONS : [ ( ( Symbol , TokenType ) , ast:: InlineAsmOptions ) ;
398+ ast:: InlineAsmOptions :: COUNT ] = [
399+ ( exp ! ( Pure ) , ast:: InlineAsmOptions :: PURE ) ,
400+ ( exp ! ( Nomem ) , ast:: InlineAsmOptions :: NOMEM ) ,
401+ ( exp ! ( Readonly ) , ast:: InlineAsmOptions :: READONLY ) ,
402+ ( exp ! ( PreservesFlags ) , ast:: InlineAsmOptions :: PRESERVES_FLAGS ) ,
403+ ( exp ! ( Noreturn ) , ast:: InlineAsmOptions :: NORETURN ) ,
404+ ( exp ! ( Nostack ) , ast:: InlineAsmOptions :: NOSTACK ) ,
405+ ( exp ! ( MayUnwind ) , ast:: InlineAsmOptions :: MAY_UNWIND ) ,
406+ ( exp ! ( AttSyntax ) , ast:: InlineAsmOptions :: ATT_SYNTAX ) ,
407+ ( exp ! ( Raw ) , ast:: InlineAsmOptions :: RAW ) ,
406408 ] ;
407409
408410 ' blk: {
409- for ( symbol , option) in OPTIONS {
411+ for ( ( sym , token_type ) , option) in OPTIONS {
410412 let kw_matched = if asm_macro. is_supported_option ( option) {
411- p. eat_keyword ( symbol )
413+ p. eat_keyword ( ( sym , token_type ) )
412414 } else {
413- p. eat_keyword_noexpect ( symbol )
415+ p. eat_keyword_noexpect ( sym )
414416 } ;
415417
416418 if kw_matched {
417- try_set_option ( p, args, asm_macro, symbol , option) ;
419+ try_set_option ( p, args, asm_macro, sym , option) ;
418420 break ' blk;
419421 }
420422 }
@@ -423,10 +425,10 @@ fn parse_options<'a>(
423425 }
424426
425427 // Allow trailing commas
426- if p. eat ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) {
428+ if p. eat ( exp ! ( CloseParen ) ) {
427429 break ;
428430 }
429- p. expect ( & token :: Comma ) ?;
431+ p. expect ( exp ! ( Comma ) ) ?;
430432 }
431433
432434 let new_span = span_start. to ( p. prev_token . span ) ;
@@ -438,14 +440,14 @@ fn parse_options<'a>(
438440fn parse_clobber_abi < ' a > ( p : & mut Parser < ' a > , args : & mut AsmArgs ) -> PResult < ' a , ( ) > {
439441 let span_start = p. prev_token . span ;
440442
441- p. expect ( & token :: OpenDelim ( Delimiter :: Parenthesis ) ) ?;
443+ p. expect ( exp ! ( OpenParen ) ) ?;
442444
443- if p. eat ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) {
445+ if p. eat ( exp ! ( CloseParen ) ) {
444446 return Err ( p. dcx ( ) . create_err ( errors:: NonABI { span : p. token . span } ) ) ;
445447 }
446448
447449 let mut new_abis = Vec :: new ( ) ;
448- while !p. eat ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) {
450+ while !p. eat ( exp ! ( CloseParen ) ) {
449451 match p. parse_str_lit ( ) {
450452 Ok ( str_lit) => {
451453 new_abis. push ( ( str_lit. symbol_unescaped , str_lit. span ) ) ;
@@ -457,10 +459,10 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
457459 } ;
458460
459461 // Allow trailing commas
460- if p. eat ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) {
462+ if p. eat ( exp ! ( CloseParen ) ) {
461463 break ;
462464 }
463- p. expect ( & token :: Comma ) ?;
465+ p. expect ( exp ! ( Comma ) ) ?;
464466 }
465467
466468 let full_span = span_start. to ( p. prev_token . span ) ;
@@ -483,7 +485,7 @@ fn parse_reg<'a>(
483485 p : & mut Parser < ' a > ,
484486 explicit_reg : & mut bool ,
485487) -> PResult < ' a , ast:: InlineAsmRegOrRegClass > {
486- p. expect ( & token :: OpenDelim ( Delimiter :: Parenthesis ) ) ?;
488+ p. expect ( exp ! ( OpenParen ) ) ?;
487489 let result = match p. token . uninterpolate ( ) . kind {
488490 token:: Ident ( name, IdentIsRaw :: No ) => ast:: InlineAsmRegOrRegClass :: RegClass ( name) ,
489491 token:: Literal ( token:: Lit { kind : token:: LitKind :: Str , symbol, suffix : _ } ) => {
@@ -497,7 +499,7 @@ fn parse_reg<'a>(
497499 }
498500 } ;
499501 p. bump ( ) ;
500- p. expect ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) ?;
502+ p. expect ( exp ! ( CloseParen ) ) ?;
501503 Ok ( result)
502504}
503505
0 commit comments