@@ -62,9 +62,9 @@ fn eat_operand_keyword<'a>(
62
62
63
63
/// A parsed list of attributes that is not attached to any item.
64
64
/// Used to check whether `asm!` arguments are configured out.
65
- struct AsmAttrList ( ast:: AttrVec ) ;
65
+ struct AsmAttrVec ( ast:: AttrVec ) ;
66
66
67
- impl AsmAttrList {
67
+ impl AsmAttrVec {
68
68
fn parse < ' a > ( ecx : & ExtCtxt < ' a > , p : & mut Parser < ' a > ) -> PResult < ' a , Self > {
69
69
let span_start = p. token . span ;
70
70
@@ -86,6 +86,28 @@ impl AsmAttrList {
86
86
Ok ( Self ( attributes) )
87
87
}
88
88
}
89
+ impl ast:: HasAttrs for AsmAttrVec {
90
+ // Follows `ast::Expr`.
91
+ const SUPPORTS_CUSTOM_INNER_ATTRS : bool = false ;
92
+
93
+ fn attrs ( & self ) -> & [ rustc_ast:: Attribute ] {
94
+ & self . 0
95
+ }
96
+
97
+ fn visit_attrs ( & mut self , f : impl FnOnce ( & mut rustc_ast:: AttrVec ) ) {
98
+ f ( & mut self . 0 )
99
+ }
100
+ }
101
+
102
+ impl ast:: HasTokens for AsmAttrVec {
103
+ fn tokens ( & self ) -> Option < & rustc_ast:: tokenstream:: LazyAttrTokenStream > {
104
+ None
105
+ }
106
+
107
+ fn tokens_mut ( & mut self ) -> Option < & mut Option < rustc_ast:: tokenstream:: LazyAttrTokenStream > > {
108
+ None
109
+ }
110
+ }
89
111
90
112
fn parse_args < ' a > (
91
113
ecx : & ExtCtxt < ' a > ,
@@ -107,11 +129,18 @@ pub fn parse_asm_args<'a>(
107
129
) -> PResult < ' a , AsmArgs > {
108
130
let dcx = p. dcx ( ) ;
109
131
132
+ let strip_unconfigured = rustc_expand:: config:: StripUnconfigured {
133
+ sess : ecx. sess ,
134
+ features : Some ( ecx. ecfg . features ) ,
135
+ config_tokens : false ,
136
+ lint_node_id : ecx. current_expansion . lint_node_id ,
137
+ } ;
138
+
110
139
if p. token == token:: Eof {
111
140
return Err ( dcx. create_err ( errors:: AsmRequiresTemplate { span : sp } ) ) ;
112
141
}
113
142
114
- let _attributes = AsmAttrList :: parse ( ecx, p) ?;
143
+ let _attributes = AsmAttrVec :: parse ( ecx, p) ?;
115
144
let first_template = p. parse_expr ( ) ?;
116
145
let mut args = AsmArgs {
117
146
templates : vec ! [ first_template] ,
@@ -138,12 +167,16 @@ pub fn parse_asm_args<'a>(
138
167
break ;
139
168
} // accept trailing commas
140
169
141
- let _attributes = AsmAttrList :: parse ( ecx, p) ?;
170
+ let attributes = AsmAttrVec :: parse ( ecx, p) ?;
171
+ let is_configured_out = strip_unconfigured. configure ( attributes) . is_none ( ) ;
142
172
143
173
// Parse clobber_abi
144
174
if p. eat_keyword ( exp ! ( ClobberAbi ) ) {
145
- parse_clobber_abi ( p, & mut args) ?;
146
- allow_templates = false ;
175
+ let new_abis = parse_clobber_abi ( p) ?;
176
+ if !is_configured_out {
177
+ args. clobber_abis . extend ( new_abis) ;
178
+ allow_templates = false ;
179
+ }
147
180
continue ;
148
181
}
149
182
@@ -466,7 +499,7 @@ fn parse_options<'a>(
466
499
Ok ( ( ) )
467
500
}
468
501
469
- fn parse_clobber_abi < ' a > ( p : & mut Parser < ' a > , args : & mut AsmArgs ) -> PResult < ' a , ( ) > {
502
+ fn parse_clobber_abi < ' a > ( p : & mut Parser < ' a > ) -> PResult < ' a , Vec < ( Symbol , Span ) > > {
470
503
let span_start = p. prev_token . span ;
471
504
472
505
p. expect ( exp ! ( OpenParen ) ) ?;
@@ -497,17 +530,9 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
497
530
let full_span = span_start. to ( p. prev_token . span ) ;
498
531
499
532
match & new_abis[ ..] {
500
- // should have errored above during parsing
501
- [ ] => unreachable ! ( ) ,
502
- [ ( abi, _span) ] => args. clobber_abis . push ( ( * abi, full_span) ) ,
503
- abis => {
504
- for ( abi, span) in abis {
505
- args. clobber_abis . push ( ( * abi, * span) ) ;
506
- }
507
- }
533
+ [ ( abi, _span) ] => Ok ( vec ! [ ( * abi, full_span) ] ) ,
534
+ _ => Ok ( new_abis) ,
508
535
}
509
-
510
- Ok ( ( ) )
511
536
}
512
537
513
538
fn parse_reg < ' a > (
0 commit comments