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:: { ErrorGuaranteed , Ident , InnerSpan , Span , Symbol , kw, sym } ;
13+ use rustc_span:: { ErrorGuaranteed , Ident , InnerSpan , Span , Symbol , kw} ;
1414use rustc_target:: asm:: InlineAsmArch ;
1515use smallvec:: smallvec;
1616use { rustc_ast as ast, rustc_parse_format as parse} ;
@@ -38,16 +38,16 @@ pub struct AsmArgs {
3838/// - `Err(_)` if the current token matches the keyword, but was not expected
3939fn eat_operand_keyword < ' a > (
4040 p : & mut Parser < ' a > ,
41- symbol : Symbol ,
41+ exp : ExpKeywordPair ,
4242 asm_macro : AsmMacro ,
4343) -> PResult < ' a , bool > {
4444 if matches ! ( asm_macro, AsmMacro :: Asm ) {
45- Ok ( p. eat_keyword ( symbol ) )
45+ Ok ( p. eat_keyword ( exp ) )
4646 } else {
4747 let span = p. token . span ;
48- if p. eat_keyword_noexpect ( symbol ) {
48+ if p. eat_keyword_noexpect ( exp . kw ) {
4949 // in gets printed as `r#in` otherwise
50- let symbol = if symbol == kw:: In { "in" } else { symbol . as_str ( ) } ;
50+ let symbol = if exp . kw == kw:: In { "in" } else { exp . kw . as_str ( ) } ;
5151 Err ( p. dcx ( ) . create_err ( errors:: AsmUnsupportedOperand {
5252 span,
5353 symbol,
@@ -95,28 +95,28 @@ pub fn parse_asm_args<'a>(
9595
9696 let mut allow_templates = true ;
9797 while p. token != token:: Eof {
98- if !p. eat ( & token :: Comma ) {
98+ if !p. eat ( exp ! ( Comma ) ) {
9999 if allow_templates {
100100 // After a template string, we always expect *only* a comma...
101101 return Err ( dcx. create_err ( errors:: AsmExpectedComma { span : p. token . span } ) ) ;
102102 } else {
103103 // ...after that delegate to `expect` to also include the other expected tokens.
104- return Err ( p. expect ( & token :: Comma ) . err ( ) . unwrap ( ) ) ;
104+ return Err ( p. expect ( exp ! ( Comma ) ) . err ( ) . unwrap ( ) ) ;
105105 }
106106 }
107107 if p. token == token:: Eof {
108108 break ;
109109 } // accept trailing commas
110110
111111 // Parse clobber_abi
112- if p. eat_keyword ( sym :: clobber_abi ) {
112+ if p. eat_keyword ( exp ! ( ClobberAbi ) ) {
113113 parse_clobber_abi ( p, & mut args) ?;
114114 allow_templates = false ;
115115 continue ;
116116 }
117117
118118 // Parse options
119- if p. eat_keyword ( sym :: options ) {
119+ if p. eat_keyword ( exp ! ( Options ) ) {
120120 parse_options ( p, & mut args, asm_macro) ?;
121121 allow_templates = false ;
122122 continue ;
@@ -128,65 +128,65 @@ pub fn parse_asm_args<'a>(
128128 let name = if p. token . is_ident ( ) && p. look_ahead ( 1 , |t| * t == token:: Eq ) {
129129 let ( ident, _) = p. token . ident ( ) . unwrap ( ) ;
130130 p. bump ( ) ;
131- p. expect ( & token :: Eq ) ?;
131+ p. expect ( exp ! ( Eq ) ) ?;
132132 allow_templates = false ;
133133 Some ( ident. name )
134134 } else {
135135 None
136136 } ;
137137
138138 let mut explicit_reg = false ;
139- let op = if eat_operand_keyword ( p, kw :: In , asm_macro) ? {
139+ let op = if eat_operand_keyword ( p, exp ! ( In ) , asm_macro) ? {
140140 let reg = parse_reg ( p, & mut explicit_reg) ?;
141- if p. eat_keyword ( kw :: Underscore ) {
141+ if p. eat_keyword ( exp ! ( Underscore ) ) {
142142 let err = dcx. create_err ( errors:: AsmUnderscoreInput { span : p. token . span } ) ;
143143 return Err ( err) ;
144144 }
145145 let expr = p. parse_expr ( ) ?;
146146 ast:: InlineAsmOperand :: In { reg, expr }
147- } else if eat_operand_keyword ( p, sym :: out , asm_macro) ? {
147+ } else if eat_operand_keyword ( p, exp ! ( Out ) , asm_macro) ? {
148148 let reg = parse_reg ( p, & mut explicit_reg) ?;
149- let expr = if p. eat_keyword ( kw :: Underscore ) { None } else { Some ( p. parse_expr ( ) ?) } ;
149+ let expr = if p. eat_keyword ( exp ! ( Underscore ) ) { None } else { Some ( p. parse_expr ( ) ?) } ;
150150 ast:: InlineAsmOperand :: Out { reg, expr, late : false }
151- } else if eat_operand_keyword ( p, sym :: lateout , asm_macro) ? {
151+ } else if eat_operand_keyword ( p, exp ! ( Lateout ) , asm_macro) ? {
152152 let reg = parse_reg ( p, & mut explicit_reg) ?;
153- let expr = if p. eat_keyword ( kw :: Underscore ) { None } else { Some ( p. parse_expr ( ) ?) } ;
153+ let expr = if p. eat_keyword ( exp ! ( Underscore ) ) { None } else { Some ( p. parse_expr ( ) ?) } ;
154154 ast:: InlineAsmOperand :: Out { reg, expr, late : true }
155- } else if eat_operand_keyword ( p, sym :: inout , asm_macro) ? {
155+ } else if eat_operand_keyword ( p, exp ! ( Inout ) , asm_macro) ? {
156156 let reg = parse_reg ( p, & mut explicit_reg) ?;
157- if p. eat_keyword ( kw :: Underscore ) {
157+ if p. eat_keyword ( exp ! ( Underscore ) ) {
158158 let err = dcx. create_err ( errors:: AsmUnderscoreInput { span : p. token . span } ) ;
159159 return Err ( err) ;
160160 }
161161 let expr = p. parse_expr ( ) ?;
162- if p. eat ( & token :: FatArrow ) {
162+ if p. eat ( exp ! ( FatArrow ) ) {
163163 let out_expr =
164- if p. eat_keyword ( kw :: Underscore ) { None } else { Some ( p. parse_expr ( ) ?) } ;
164+ if p. eat_keyword ( exp ! ( Underscore ) ) { None } else { Some ( p. parse_expr ( ) ?) } ;
165165 ast:: InlineAsmOperand :: SplitInOut { reg, in_expr : expr, out_expr, late : false }
166166 } else {
167167 ast:: InlineAsmOperand :: InOut { reg, expr, late : false }
168168 }
169- } else if eat_operand_keyword ( p, sym :: inlateout , asm_macro) ? {
169+ } else if eat_operand_keyword ( p, exp ! ( Inlateout ) , asm_macro) ? {
170170 let reg = parse_reg ( p, & mut explicit_reg) ?;
171- if p. eat_keyword ( kw :: Underscore ) {
171+ if p. eat_keyword ( exp ! ( Underscore ) ) {
172172 let err = dcx. create_err ( errors:: AsmUnderscoreInput { span : p. token . span } ) ;
173173 return Err ( err) ;
174174 }
175175 let expr = p. parse_expr ( ) ?;
176- if p. eat ( & token :: FatArrow ) {
176+ if p. eat ( exp ! ( FatArrow ) ) {
177177 let out_expr =
178- if p. eat_keyword ( kw :: Underscore ) { None } else { Some ( p. parse_expr ( ) ?) } ;
178+ if p. eat_keyword ( exp ! ( Underscore ) ) { None } else { Some ( p. parse_expr ( ) ?) } ;
179179 ast:: InlineAsmOperand :: SplitInOut { reg, in_expr : expr, out_expr, late : true }
180180 } else {
181181 ast:: InlineAsmOperand :: InOut { reg, expr, late : true }
182182 }
183- } else if eat_operand_keyword ( p, sym :: label , asm_macro) ? {
183+ } else if eat_operand_keyword ( p, exp ! ( Label ) , asm_macro) ? {
184184 let block = p. parse_block ( ) ?;
185185 ast:: InlineAsmOperand :: Label { block }
186- } else if p. eat_keyword ( kw :: Const ) {
186+ } else if p. eat_keyword ( exp ! ( Const ) ) {
187187 let anon_const = p. parse_expr_anon_const ( ) ?;
188188 ast:: InlineAsmOperand :: Const { anon_const }
189- } else if p. eat_keyword ( sym :: sym ) {
189+ } else if p. eat_keyword ( exp ! ( Sym ) ) {
190190 let expr = p. parse_expr ( ) ?;
191191 let ast:: ExprKind :: Path ( qself, path) = & expr. kind else {
192192 let err = dcx. create_err ( errors:: AsmSymNoPath { span : expr. span } ) ;
@@ -389,31 +389,31 @@ fn parse_options<'a>(
389389) -> PResult < ' a , ( ) > {
390390 let span_start = p. prev_token . span ;
391391
392- p. expect ( & token :: OpenDelim ( Delimiter :: Parenthesis ) ) ?;
393-
394- while !p. eat ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) {
395- const OPTIONS : [ ( Symbol , ast:: InlineAsmOptions ) ; ast:: InlineAsmOptions :: COUNT ] = [
396- ( sym :: pure , ast:: InlineAsmOptions :: PURE ) ,
397- ( sym :: nomem , ast:: InlineAsmOptions :: NOMEM ) ,
398- ( sym :: readonly , ast:: InlineAsmOptions :: READONLY ) ,
399- ( sym :: preserves_flags , ast:: InlineAsmOptions :: PRESERVES_FLAGS ) ,
400- ( sym :: noreturn , ast:: InlineAsmOptions :: NORETURN ) ,
401- ( sym :: nostack , ast:: InlineAsmOptions :: NOSTACK ) ,
402- ( sym :: may_unwind , ast:: InlineAsmOptions :: MAY_UNWIND ) ,
403- ( sym :: att_syntax , ast:: InlineAsmOptions :: ATT_SYNTAX ) ,
404- ( kw :: Raw , ast:: InlineAsmOptions :: RAW ) ,
392+ p. expect ( exp ! ( OpenParen ) ) ?;
393+
394+ while !p. eat ( exp ! ( CloseParen ) ) {
395+ const OPTIONS : [ ( ExpKeywordPair , ast:: InlineAsmOptions ) ; ast:: InlineAsmOptions :: COUNT ] = [
396+ ( exp ! ( Pure ) , ast:: InlineAsmOptions :: PURE ) ,
397+ ( exp ! ( Nomem ) , ast:: InlineAsmOptions :: NOMEM ) ,
398+ ( exp ! ( Readonly ) , ast:: InlineAsmOptions :: READONLY ) ,
399+ ( exp ! ( PreservesFlags ) , ast:: InlineAsmOptions :: PRESERVES_FLAGS ) ,
400+ ( exp ! ( Noreturn ) , ast:: InlineAsmOptions :: NORETURN ) ,
401+ ( exp ! ( Nostack ) , ast:: InlineAsmOptions :: NOSTACK ) ,
402+ ( exp ! ( MayUnwind ) , ast:: InlineAsmOptions :: MAY_UNWIND ) ,
403+ ( exp ! ( AttSyntax ) , ast:: InlineAsmOptions :: ATT_SYNTAX ) ,
404+ ( exp ! ( Raw ) , ast:: InlineAsmOptions :: RAW ) ,
405405 ] ;
406406
407407 ' blk: {
408- for ( symbol , option) in OPTIONS {
408+ for ( exp , option) in OPTIONS {
409409 let kw_matched = if asm_macro. is_supported_option ( option) {
410- p. eat_keyword ( symbol )
410+ p. eat_keyword ( exp )
411411 } else {
412- p. eat_keyword_noexpect ( symbol )
412+ p. eat_keyword_noexpect ( exp . kw )
413413 } ;
414414
415415 if kw_matched {
416- try_set_option ( p, args, asm_macro, symbol , option) ;
416+ try_set_option ( p, args, asm_macro, exp . kw , option) ;
417417 break ' blk;
418418 }
419419 }
@@ -422,10 +422,10 @@ fn parse_options<'a>(
422422 }
423423
424424 // Allow trailing commas
425- if p. eat ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) {
425+ if p. eat ( exp ! ( CloseParen ) ) {
426426 break ;
427427 }
428- p. expect ( & token :: Comma ) ?;
428+ p. expect ( exp ! ( Comma ) ) ?;
429429 }
430430
431431 let new_span = span_start. to ( p. prev_token . span ) ;
@@ -437,14 +437,14 @@ fn parse_options<'a>(
437437fn parse_clobber_abi < ' a > ( p : & mut Parser < ' a > , args : & mut AsmArgs ) -> PResult < ' a , ( ) > {
438438 let span_start = p. prev_token . span ;
439439
440- p. expect ( & token :: OpenDelim ( Delimiter :: Parenthesis ) ) ?;
440+ p. expect ( exp ! ( OpenParen ) ) ?;
441441
442- if p. eat ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) {
442+ if p. eat ( exp ! ( CloseParen ) ) {
443443 return Err ( p. dcx ( ) . create_err ( errors:: NonABI { span : p. token . span } ) ) ;
444444 }
445445
446446 let mut new_abis = Vec :: new ( ) ;
447- while !p. eat ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) {
447+ while !p. eat ( exp ! ( CloseParen ) ) {
448448 match p. parse_str_lit ( ) {
449449 Ok ( str_lit) => {
450450 new_abis. push ( ( str_lit. symbol_unescaped , str_lit. span ) ) ;
@@ -456,10 +456,10 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
456456 } ;
457457
458458 // Allow trailing commas
459- if p. eat ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) {
459+ if p. eat ( exp ! ( CloseParen ) ) {
460460 break ;
461461 }
462- p. expect ( & token :: Comma ) ?;
462+ p. expect ( exp ! ( Comma ) ) ?;
463463 }
464464
465465 let full_span = span_start. to ( p. prev_token . span ) ;
@@ -482,7 +482,7 @@ fn parse_reg<'a>(
482482 p : & mut Parser < ' a > ,
483483 explicit_reg : & mut bool ,
484484) -> PResult < ' a , ast:: InlineAsmRegOrRegClass > {
485- p. expect ( & token :: OpenDelim ( Delimiter :: Parenthesis ) ) ?;
485+ p. expect ( exp ! ( OpenParen ) ) ?;
486486 let result = match p. token . uninterpolate ( ) . kind {
487487 token:: Ident ( name, IdentIsRaw :: No ) => ast:: InlineAsmRegOrRegClass :: RegClass ( name) ,
488488 token:: Literal ( token:: Lit { kind : token:: LitKind :: Str , symbol, suffix : _ } ) => {
@@ -496,7 +496,7 @@ fn parse_reg<'a>(
496496 }
497497 } ;
498498 p. bump ( ) ;
499- p. expect ( & token :: CloseDelim ( Delimiter :: Parenthesis ) ) ?;
499+ p. expect ( exp ! ( CloseParen ) ) ?;
500500 Ok ( result)
501501}
502502
0 commit comments