11use ast:: token:: IdentIsRaw ;
22use lint:: BuiltinLintDiag ;
3- use rustc_ast:: AsmMacro ;
43use rustc_ast:: ptr:: P ;
5- use rustc_ast:: token:: { self , Delimiter } ;
64use rustc_ast:: tokenstream:: TokenStream ;
5+ use rustc_ast:: { AsmMacro , token} ;
76use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap } ;
87use rustc_errors:: PResult ;
98use rustc_expand:: base:: * ;
109use rustc_index:: bit_set:: GrowableBitSet ;
11- use rustc_parse:: parser:: Parser ;
10+ use rustc_parse:: exp;
11+ use rustc_parse:: parser:: { ExpKeywordPair , Parser } ;
1212use rustc_session:: lint;
13- use rustc_span:: symbol:: { Ident , Symbol , kw, sym } ;
13+ use rustc_span:: symbol:: { Ident , Symbol , kw} ;
1414use rustc_span:: { ErrorGuaranteed , InnerSpan , Span } ;
1515use rustc_target:: asm:: InlineAsmArch ;
1616use smallvec:: smallvec;
@@ -39,16 +39,16 @@ pub struct AsmArgs {
3939/// - `Err(_)` if the current token matches the keyword, but was not expected
4040fn eat_operand_keyword < ' a > (
4141 p : & mut Parser < ' a > ,
42- symbol : Symbol ,
42+ exp : ExpKeywordPair ,
4343 asm_macro : AsmMacro ,
4444) -> PResult < ' a , bool > {
4545 if matches ! ( asm_macro, AsmMacro :: Asm ) {
46- Ok ( p. eat_keyword ( symbol ) )
46+ Ok ( p. eat_keyword ( exp ) )
4747 } else {
4848 let span = p. token . span ;
49- if p. eat_keyword_noexpect ( symbol ) {
49+ if p. eat_keyword_noexpect ( exp . kw ) {
5050 // in gets printed as `r#in` otherwise
51- let symbol = if symbol == kw:: In { "in" } else { symbol . as_str ( ) } ;
51+ let symbol = if exp . kw == kw:: In { "in" } else { exp . kw . as_str ( ) } ;
5252 Err ( p. dcx ( ) . create_err ( errors:: AsmUnsupportedOperand {
5353 span,
5454 symbol,
@@ -96,28 +96,28 @@ pub fn parse_asm_args<'a>(
9696
9797 let mut allow_templates = true ;
9898 while p. token != token:: Eof {
99- if !p. eat ( & token :: Comma ) {
99+ if !p. eat ( exp ! ( Comma ) ) {
100100 if allow_templates {
101101 // After a template string, we always expect *only* a comma...
102102 return Err ( dcx. create_err ( errors:: AsmExpectedComma { span : p. token . span } ) ) ;
103103 } else {
104104 // ...after that delegate to `expect` to also include the other expected tokens.
105- return Err ( p. expect ( & token :: Comma ) . err ( ) . unwrap ( ) ) ;
105+ return Err ( p. expect ( exp ! ( Comma ) ) . err ( ) . unwrap ( ) ) ;
106106 }
107107 }
108108 if p. token == token:: Eof {
109109 break ;
110110 } // accept trailing commas
111111
112112 // Parse clobber_abi
113- if p. eat_keyword ( sym :: clobber_abi ) {
113+ if p. eat_keyword ( exp ! ( ClobberAbi ) ) {
114114 parse_clobber_abi ( p, & mut args) ?;
115115 allow_templates = false ;
116116 continue ;
117117 }
118118
119119 // Parse options
120- if p. eat_keyword ( sym :: options ) {
120+ if p. eat_keyword ( exp ! ( Options ) ) {
121121 parse_options ( p, & mut args, asm_macro) ?;
122122 allow_templates = false ;
123123 continue ;
@@ -129,65 +129,65 @@ pub fn parse_asm_args<'a>(
129129 let name = if p. token . is_ident ( ) && p. look_ahead ( 1 , |t| * t == token:: Eq ) {
130130 let ( ident, _) = p. token . ident ( ) . unwrap ( ) ;
131131 p. bump ( ) ;
132- p. expect ( & token :: Eq ) ?;
132+ p. expect ( exp ! ( Eq ) ) ?;
133133 allow_templates = false ;
134134 Some ( ident. name )
135135 } else {
136136 None
137137 } ;
138138
139139 let mut explicit_reg = false ;
140- let op = if eat_operand_keyword ( p, kw :: In , asm_macro) ? {
140+ let op = if eat_operand_keyword ( p, exp ! ( In ) , asm_macro) ? {
141141 let reg = parse_reg ( p, & mut explicit_reg) ?;
142- if p. eat_keyword ( kw :: Underscore ) {
142+ if p. eat_keyword ( exp ! ( Underscore ) ) {
143143 let err = dcx. create_err ( errors:: AsmUnderscoreInput { span : p. token . span } ) ;
144144 return Err ( err) ;
145145 }
146146 let expr = p. parse_expr ( ) ?;
147147 ast:: InlineAsmOperand :: In { reg, expr }
148- } else if eat_operand_keyword ( p, sym :: out , asm_macro) ? {
148+ } else if eat_operand_keyword ( p, exp ! ( Out ) , asm_macro) ? {
149149 let reg = parse_reg ( p, & mut explicit_reg) ?;
150- let expr = if p. eat_keyword ( kw :: Underscore ) { None } else { Some ( p. parse_expr ( ) ?) } ;
150+ let expr = if p. eat_keyword ( exp ! ( Underscore ) ) { None } else { Some ( p. parse_expr ( ) ?) } ;
151151 ast:: InlineAsmOperand :: Out { reg, expr, late : false }
152- } else if eat_operand_keyword ( p, sym :: lateout , asm_macro) ? {
152+ } else if eat_operand_keyword ( p, exp ! ( Lateout ) , asm_macro) ? {
153153 let reg = parse_reg ( p, & mut explicit_reg) ?;
154- let expr = if p. eat_keyword ( kw :: Underscore ) { None } else { Some ( p. parse_expr ( ) ?) } ;
154+ let expr = if p. eat_keyword ( exp ! ( Underscore ) ) { None } else { Some ( p. parse_expr ( ) ?) } ;
155155 ast:: InlineAsmOperand :: Out { reg, expr, late : true }
156- } else if eat_operand_keyword ( p, sym :: inout , asm_macro) ? {
156+ } else if eat_operand_keyword ( p, exp ! ( Inout ) , asm_macro) ? {
157157 let reg = parse_reg ( p, & mut explicit_reg) ?;
158- if p. eat_keyword ( kw :: Underscore ) {
158+ if p. eat_keyword ( exp ! ( Underscore ) ) {
159159 let err = dcx. create_err ( errors:: AsmUnderscoreInput { span : p. token . span } ) ;
160160 return Err ( err) ;
161161 }
162162 let expr = p. parse_expr ( ) ?;
163- if p. eat ( & token :: FatArrow ) {
163+ if p. eat ( exp ! ( FatArrow ) ) {
164164 let out_expr =
165- if p. eat_keyword ( kw :: Underscore ) { None } else { Some ( p. parse_expr ( ) ?) } ;
165+ if p. eat_keyword ( exp ! ( Underscore ) ) { None } else { Some ( p. parse_expr ( ) ?) } ;
166166 ast:: InlineAsmOperand :: SplitInOut { reg, in_expr : expr, out_expr, late : false }
167167 } else {
168168 ast:: InlineAsmOperand :: InOut { reg, expr, late : false }
169169 }
170- } else if eat_operand_keyword ( p, sym :: inlateout , asm_macro) ? {
170+ } else if eat_operand_keyword ( p, exp ! ( Inlateout ) , asm_macro) ? {
171171 let reg = parse_reg ( p, & mut explicit_reg) ?;
172- if p. eat_keyword ( kw :: Underscore ) {
172+ if p. eat_keyword ( exp ! ( Underscore ) ) {
173173 let err = dcx. create_err ( errors:: AsmUnderscoreInput { span : p. token . span } ) ;
174174 return Err ( err) ;
175175 }
176176 let expr = p. parse_expr ( ) ?;
177- if p. eat ( & token :: FatArrow ) {
177+ if p. eat ( exp ! ( FatArrow ) ) {
178178 let out_expr =
179- if p. eat_keyword ( kw :: Underscore ) { None } else { Some ( p. parse_expr ( ) ?) } ;
179+ if p. eat_keyword ( exp ! ( Underscore ) ) { None } else { Some ( p. parse_expr ( ) ?) } ;
180180 ast:: InlineAsmOperand :: SplitInOut { reg, in_expr : expr, out_expr, late : true }
181181 } else {
182182 ast:: InlineAsmOperand :: InOut { reg, expr, late : true }
183183 }
184- } else if eat_operand_keyword ( p, sym :: label , asm_macro) ? {
184+ } else if eat_operand_keyword ( p, exp ! ( Label ) , asm_macro) ? {
185185 let block = p. parse_block ( ) ?;
186186 ast:: InlineAsmOperand :: Label { block }
187- } else if p. eat_keyword ( kw :: Const ) {
187+ } else if p. eat_keyword ( exp ! ( Const ) ) {
188188 let anon_const = p. parse_expr_anon_const ( ) ?;
189189 ast:: InlineAsmOperand :: Const { anon_const }
190- } else if p. eat_keyword ( sym :: sym ) {
190+ } else if p. eat_keyword ( exp ! ( Sym ) ) {
191191 let expr = p. parse_expr ( ) ?;
192192 let ast:: ExprKind :: Path ( qself, path) = & expr. kind else {
193193 let err = dcx. create_err ( errors:: AsmSymNoPath { span : expr. span } ) ;
@@ -390,31 +390,31 @@ fn parse_options<'a>(
390390) -> PResult < ' a , ( ) > {
391391 let span_start = p. prev_token . span ;
392392
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 ) ,
393+ p. expect ( exp ! ( OpenParen ) ) ?;
394+
395+ while !p. eat ( exp ! ( CloseParen ) ) {
396+ const OPTIONS : [ ( ExpKeywordPair , ast:: InlineAsmOptions ) ; ast:: InlineAsmOptions :: COUNT ] = [
397+ ( exp ! ( Pure ) , ast:: InlineAsmOptions :: PURE ) ,
398+ ( exp ! ( Nomem ) , ast:: InlineAsmOptions :: NOMEM ) ,
399+ ( exp ! ( Readonly ) , ast:: InlineAsmOptions :: READONLY ) ,
400+ ( exp ! ( PreservesFlags ) , ast:: InlineAsmOptions :: PRESERVES_FLAGS ) ,
401+ ( exp ! ( Noreturn ) , ast:: InlineAsmOptions :: NORETURN ) ,
402+ ( exp ! ( Nostack ) , ast:: InlineAsmOptions :: NOSTACK ) ,
403+ ( exp ! ( MayUnwind ) , ast:: InlineAsmOptions :: MAY_UNWIND ) ,
404+ ( exp ! ( AttSyntax ) , ast:: InlineAsmOptions :: ATT_SYNTAX ) ,
405+ ( exp ! ( Raw ) , ast:: InlineAsmOptions :: RAW ) ,
406406 ] ;
407407
408408 ' blk: {
409- for ( symbol , option) in OPTIONS {
409+ for ( exp , option) in OPTIONS {
410410 let kw_matched = if asm_macro. is_supported_option ( option) {
411- p. eat_keyword ( symbol )
411+ p. eat_keyword ( exp )
412412 } else {
413- p. eat_keyword_noexpect ( symbol )
413+ p. eat_keyword_noexpect ( exp . kw )
414414 } ;
415415
416416 if kw_matched {
417- try_set_option ( p, args, asm_macro, symbol , option) ;
417+ try_set_option ( p, args, asm_macro, exp . kw , option) ;
418418 break ' blk;
419419 }
420420 }
@@ -423,10 +423,10 @@ fn parse_options<'a>(
423423 }
424424
425425 // Allow trailing commas
426- if p. eat ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) {
426+ if p. eat ( exp ! ( CloseParen ) ) {
427427 break ;
428428 }
429- p. expect ( & token :: Comma ) ?;
429+ p. expect ( exp ! ( Comma ) ) ?;
430430 }
431431
432432 let new_span = span_start. to ( p. prev_token . span ) ;
@@ -438,14 +438,14 @@ fn parse_options<'a>(
438438fn parse_clobber_abi < ' a > ( p : & mut Parser < ' a > , args : & mut AsmArgs ) -> PResult < ' a , ( ) > {
439439 let span_start = p. prev_token . span ;
440440
441- p. expect ( & token :: OpenDelim ( Delimiter :: Parenthesis ) ) ?;
441+ p. expect ( exp ! ( OpenParen ) ) ?;
442442
443- if p. eat ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) {
443+ if p. eat ( exp ! ( CloseParen ) ) {
444444 return Err ( p. dcx ( ) . create_err ( errors:: NonABI { span : p. token . span } ) ) ;
445445 }
446446
447447 let mut new_abis = Vec :: new ( ) ;
448- while !p. eat ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) {
448+ while !p. eat ( exp ! ( CloseParen ) ) {
449449 match p. parse_str_lit ( ) {
450450 Ok ( str_lit) => {
451451 new_abis. push ( ( str_lit. symbol_unescaped , str_lit. span ) ) ;
@@ -457,10 +457,10 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
457457 } ;
458458
459459 // Allow trailing commas
460- if p. eat ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) {
460+ if p. eat ( exp ! ( CloseParen ) ) {
461461 break ;
462462 }
463- p. expect ( & token :: Comma ) ?;
463+ p. expect ( exp ! ( Comma ) ) ?;
464464 }
465465
466466 let full_span = span_start. to ( p. prev_token . span ) ;
@@ -483,7 +483,7 @@ fn parse_reg<'a>(
483483 p : & mut Parser < ' a > ,
484484 explicit_reg : & mut bool ,
485485) -> PResult < ' a , ast:: InlineAsmRegOrRegClass > {
486- p. expect ( & token :: OpenDelim ( Delimiter :: Parenthesis ) ) ?;
486+ p. expect ( exp ! ( OpenParen ) ) ?;
487487 let result = match p. token . uninterpolate ( ) . kind {
488488 token:: Ident ( name, IdentIsRaw :: No ) => ast:: InlineAsmRegOrRegClass :: RegClass ( name) ,
489489 token:: Literal ( token:: Lit { kind : token:: LitKind :: Str , symbol, suffix : _ } ) => {
@@ -497,7 +497,7 @@ fn parse_reg<'a>(
497497 }
498498 } ;
499499 p. bump ( ) ;
500- p. expect ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) ?;
500+ p. expect ( exp ! ( CloseParen ) ) ?;
501501 Ok ( result)
502502}
503503
0 commit comments