Skip to content

Commit e15b0f6

Browse files
committed
cleanup parse_options
1 parent 61a9db7 commit e15b0f6

File tree

1 file changed

+22
-68
lines changed
  • compiler/rustc_builtin_macros/src

1 file changed

+22
-68
lines changed

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 22 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -209,66 +209,10 @@ pub fn parse_raw_asm_args<'a>(
209209
if p.eat_keyword(exp!(Options)) {
210210
allow_templates = false;
211211

212-
p.expect(exp!(OpenParen))?;
213-
214-
let mut options = Vec::new();
215-
216-
while !p.eat(exp!(CloseParen)) {
217-
const OPTIONS: [(ExpKeywordPair, ast::InlineAsmOptions);
218-
ast::InlineAsmOptions::COUNT] = [
219-
(exp!(Pure), ast::InlineAsmOptions::PURE),
220-
(exp!(Nomem), ast::InlineAsmOptions::NOMEM),
221-
(exp!(Readonly), ast::InlineAsmOptions::READONLY),
222-
(exp!(PreservesFlags), ast::InlineAsmOptions::PRESERVES_FLAGS),
223-
(exp!(Noreturn), ast::InlineAsmOptions::NORETURN),
224-
(exp!(Nostack), ast::InlineAsmOptions::NOSTACK),
225-
(exp!(MayUnwind), ast::InlineAsmOptions::MAY_UNWIND),
226-
(exp!(AttSyntax), ast::InlineAsmOptions::ATT_SYNTAX),
227-
(exp!(Raw), ast::InlineAsmOptions::RAW),
228-
];
229-
230-
'blk: {
231-
for (exp, option) in OPTIONS {
232-
let kw_matched = if asm_macro.is_supported_option(option) {
233-
p.eat_keyword(exp)
234-
} else {
235-
p.eat_keyword_noexpect(exp.kw)
236-
};
237-
238-
if kw_matched {
239-
let span = p.prev_token.span;
240-
let full_span =
241-
if p.token == token::Comma { span.to(p.token.span) } else { span };
242-
243-
if !asm_macro.is_supported_option(option) {
244-
// Tool-only output
245-
p.dcx().emit_err(errors::AsmUnsupportedOption {
246-
span,
247-
symbol: exp.kw,
248-
full_span,
249-
macro_name: asm_macro.macro_name(),
250-
});
251-
}
252-
253-
options.push((exp.kw, option, span, full_span));
254-
break 'blk;
255-
}
256-
}
257-
258-
return p.unexpected_any();
259-
}
260-
261-
// Allow trailing commas
262-
if p.eat(exp!(CloseParen)) {
263-
break;
264-
}
265-
p.expect(exp!(Comma))?;
266-
}
267-
268212
args.push(RawAsmArg {
269-
span: span_start.to(p.prev_token.span),
270213
attributes: ast::AttrVec::new(),
271-
kind: RawAsmArgKind::Options(options),
214+
kind: RawAsmArgKind::Options(parse_options(p, asm_macro)?),
215+
span: span_start.to(p.prev_token.span),
272216
});
273217

274218
continue;
@@ -579,13 +523,12 @@ fn try_set_option<'a>(
579523

580524
fn parse_options<'a>(
581525
p: &mut Parser<'a>,
582-
args: &mut AsmArgs,
583526
asm_macro: AsmMacro,
584-
) -> PResult<'a, ()> {
585-
let span_start = p.prev_token.span;
586-
527+
) -> PResult<'a, Vec<(Symbol, ast::InlineAsmOptions, Span, Span)>> {
587528
p.expect(exp!(OpenParen))?;
588529

530+
let mut options = Vec::new();
531+
589532
while !p.eat(exp!(CloseParen)) {
590533
const OPTIONS: [(ExpKeywordPair, ast::InlineAsmOptions); ast::InlineAsmOptions::COUNT] = [
591534
(exp!(Pure), ast::InlineAsmOptions::PURE),
@@ -608,12 +551,26 @@ fn parse_options<'a>(
608551
};
609552

610553
if kw_matched {
611-
try_set_option(p, args, asm_macro, exp.kw, option);
554+
let span = p.prev_token.span;
555+
let full_span =
556+
if p.token == token::Comma { span.to(p.token.span) } else { span };
557+
558+
if !asm_macro.is_supported_option(option) {
559+
// Tool-only output
560+
p.dcx().emit_err(errors::AsmUnsupportedOption {
561+
span,
562+
symbol: exp.kw,
563+
full_span,
564+
macro_name: asm_macro.macro_name(),
565+
});
566+
}
567+
568+
options.push((exp.kw, option, span, full_span));
612569
break 'blk;
613570
}
614571
}
615572

616-
return p.unexpected();
573+
return p.unexpected_any();
617574
}
618575

619576
// Allow trailing commas
@@ -623,10 +580,7 @@ fn parse_options<'a>(
623580
p.expect(exp!(Comma))?;
624581
}
625582

626-
let new_span = span_start.to(p.prev_token.span);
627-
args.options_spans.push(new_span);
628-
629-
Ok(())
583+
Ok(options)
630584
}
631585

632586
fn parse_clobber_abi<'a>(p: &mut Parser<'a>) -> PResult<'a, Vec<(Symbol, Span)>> {

0 commit comments

Comments
 (0)