Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c7da50d

Browse files
committed
Get option name from symbol instead of snippet
1 parent 7c5b66f commit c7da50d

File tree

1 file changed

+19
-17
lines changed
  • src/librustc_builtin_macros

1 file changed

+19
-17
lines changed

src/librustc_builtin_macros/asm.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -289,23 +289,25 @@ fn parse_args<'a>(
289289
Ok(args)
290290
}
291291

292-
fn err_duplicate_option<'a>(p: &mut Parser<'a>, span: Span) {
293-
let mut err = if let Ok(snippet) = p.sess.source_map().span_to_snippet(span) {
294-
p.sess
295-
.span_diagnostic
296-
.struct_span_err(span, &format!("the `{}` option was already provided", snippet))
297-
} else {
298-
p.sess.span_diagnostic.struct_span_err(span, "this option was already provided")
299-
};
292+
fn err_duplicate_option<'a>(p: &mut Parser<'a>, symbol: Symbol, span: Span) {
293+
let mut err = p
294+
.sess
295+
.span_diagnostic
296+
.struct_span_err(span, &format!("the `{}` option was already provided", symbol));
300297
err.span_label(span, "remove this option");
301298
err.emit();
302299
}
303300

304-
fn try_set_option<'a>(p: &mut Parser<'a>, args: &mut AsmArgs, option: ast::InlineAsmOptions) {
301+
fn try_set_option<'a>(
302+
p: &mut Parser<'a>,
303+
args: &mut AsmArgs,
304+
symbol: Symbol,
305+
option: ast::InlineAsmOptions,
306+
) {
305307
if !args.option_is_set(option) {
306308
args.options |= option;
307309
} else {
308-
err_duplicate_option(p, p.prev_token.span);
310+
err_duplicate_option(p, symbol, p.prev_token.span);
309311
}
310312
}
311313

@@ -316,20 +318,20 @@ fn parse_options<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> Result<(), Diagn
316318

317319
while !p.eat(&token::CloseDelim(token::DelimToken::Paren)) {
318320
if p.eat(&token::Ident(sym::pure, false)) {
319-
try_set_option(p, args, ast::InlineAsmOptions::PURE);
321+
try_set_option(p, args, sym::pure, ast::InlineAsmOptions::PURE);
320322
} else if p.eat(&token::Ident(sym::nomem, false)) {
321-
try_set_option(p, args, ast::InlineAsmOptions::NOMEM);
323+
try_set_option(p, args, sym::nomem, ast::InlineAsmOptions::NOMEM);
322324
} else if p.eat(&token::Ident(sym::readonly, false)) {
323-
try_set_option(p, args, ast::InlineAsmOptions::READONLY);
325+
try_set_option(p, args, sym::readonly, ast::InlineAsmOptions::READONLY);
324326
} else if p.eat(&token::Ident(sym::preserves_flags, false)) {
325-
try_set_option(p, args, ast::InlineAsmOptions::PRESERVES_FLAGS);
327+
try_set_option(p, args, sym::preserves_flags, ast::InlineAsmOptions::PRESERVES_FLAGS);
326328
} else if p.eat(&token::Ident(sym::noreturn, false)) {
327-
try_set_option(p, args, ast::InlineAsmOptions::NORETURN);
329+
try_set_option(p, args, sym::noreturn, ast::InlineAsmOptions::NORETURN);
328330
} else if p.eat(&token::Ident(sym::nostack, false)) {
329-
try_set_option(p, args, ast::InlineAsmOptions::NOSTACK);
331+
try_set_option(p, args, sym::nostack, ast::InlineAsmOptions::NOSTACK);
330332
} else {
331333
p.expect(&token::Ident(sym::att_syntax, false))?;
332-
try_set_option(p, args, ast::InlineAsmOptions::ATT_SYNTAX);
334+
try_set_option(p, args, sym::att_syntax, ast::InlineAsmOptions::ATT_SYNTAX);
333335
}
334336

335337
// Allow trailing commas

0 commit comments

Comments
 (0)