Skip to content

Commit 840176a

Browse files
committed
asm: Unify pseudo-keyword parsing using eat, rather than a final expect
Currently, `asm!` parsing uses an `expect` for the last parsed pseudo-keyword (`sym`), which makes it difficult to extend without simultaneously refactoring. Use `eat` for the last pseudo-keyword, and then add an `else` that fails parsing. No change to error output.
1 parent 4fb54ed commit 840176a

File tree

1 file changed

+3
-2
lines changed
  • src/librustc_builtin_macros

1 file changed

+3
-2
lines changed

src/librustc_builtin_macros/asm.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ fn parse_args<'a>(
135135
} else if p.eat(&token::Ident(kw::Const, false)) {
136136
let expr = p.parse_expr()?;
137137
ast::InlineAsmOperand::Const { expr }
138-
} else {
139-
p.expect(&token::Ident(sym::sym, false))?;
138+
} else if p.eat(&token::Ident(sym::sym, false)) {
140139
let expr = p.parse_expr()?;
141140
match expr.kind {
142141
ast::ExprKind::Path(..) => {}
@@ -147,6 +146,8 @@ fn parse_args<'a>(
147146
}
148147
}
149148
ast::InlineAsmOperand::Sym { expr }
149+
} else {
150+
return Err(p.expect_one_of(&[], &[]).unwrap_err());
150151
};
151152

152153
let span = span_start.to(p.prev_token.span);

0 commit comments

Comments
 (0)