Skip to content

Commit d3157c9

Browse files
committed
determine later whether an explicit reg was used
1 parent dc8fe1f commit d3157c9

File tree

1 file changed

+9
-11
lines changed
  • compiler/rustc_builtin_macros/src

1 file changed

+9
-11
lines changed

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,25 +135,24 @@ pub fn parse_asm_args<'a>(
135135
None
136136
};
137137

138-
let mut explicit_reg = false;
139138
let op = if eat_operand_keyword(p, exp!(In), asm_macro)? {
140-
let reg = parse_reg(p, &mut explicit_reg)?;
139+
let reg = parse_reg(p)?;
141140
if p.eat_keyword(exp!(Underscore)) {
142141
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
143142
return Err(err);
144143
}
145144
let expr = p.parse_expr()?;
146145
ast::InlineAsmOperand::In { reg, expr }
147146
} else if eat_operand_keyword(p, exp!(Out), asm_macro)? {
148-
let reg = parse_reg(p, &mut explicit_reg)?;
147+
let reg = parse_reg(p)?;
149148
let expr = if p.eat_keyword(exp!(Underscore)) { None } else { Some(p.parse_expr()?) };
150149
ast::InlineAsmOperand::Out { reg, expr, late: false }
151150
} else if eat_operand_keyword(p, exp!(Lateout), asm_macro)? {
152-
let reg = parse_reg(p, &mut explicit_reg)?;
151+
let reg = parse_reg(p)?;
153152
let expr = if p.eat_keyword(exp!(Underscore)) { None } else { Some(p.parse_expr()?) };
154153
ast::InlineAsmOperand::Out { reg, expr, late: true }
155154
} else if eat_operand_keyword(p, exp!(Inout), asm_macro)? {
156-
let reg = parse_reg(p, &mut explicit_reg)?;
155+
let reg = parse_reg(p)?;
157156
if p.eat_keyword(exp!(Underscore)) {
158157
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
159158
return Err(err);
@@ -167,7 +166,7 @@ pub fn parse_asm_args<'a>(
167166
ast::InlineAsmOperand::InOut { reg, expr, late: false }
168167
}
169168
} else if eat_operand_keyword(p, exp!(Inlateout), asm_macro)? {
170-
let reg = parse_reg(p, &mut explicit_reg)?;
169+
let reg = parse_reg(p)?;
171170
if p.eat_keyword(exp!(Underscore)) {
172171
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
173172
return Err(err);
@@ -223,6 +222,8 @@ pub fn parse_asm_args<'a>(
223222
p.unexpected_any()?
224223
};
225224

225+
let explicit_reg = matches!(op.reg(), Some(ast::InlineAsmRegOrRegClass::Reg(_)));
226+
226227
allow_templates = false;
227228
let span = span_start.to(p.prev_token.span);
228229
let slot = args.operands.len();
@@ -231,6 +232,7 @@ pub fn parse_asm_args<'a>(
231232
// Validate the order of named, positional & explicit register operands and
232233
// clobber_abi/options. We do this at the end once we have the full span
233234
// of the argument available.
235+
234236
if explicit_reg {
235237
if name.is_some() {
236238
dcx.emit_err(errors::AsmExplicitRegisterName { span });
@@ -478,15 +480,11 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
478480
Ok(())
479481
}
480482

481-
fn parse_reg<'a>(
482-
p: &mut Parser<'a>,
483-
explicit_reg: &mut bool,
484-
) -> PResult<'a, ast::InlineAsmRegOrRegClass> {
483+
fn parse_reg<'a>(p: &mut Parser<'a>) -> PResult<'a, ast::InlineAsmRegOrRegClass> {
485484
p.expect(exp!(OpenParen))?;
486485
let result = match p.token.uninterpolate().kind {
487486
token::Ident(name, IdentIsRaw::No) => ast::InlineAsmRegOrRegClass::RegClass(name),
488487
token::Literal(token::Lit { kind: token::LitKind::Str, symbol, suffix: _ }) => {
489-
*explicit_reg = true;
490488
ast::InlineAsmRegOrRegClass::Reg(symbol)
491489
}
492490
_ => {

0 commit comments

Comments
 (0)