diff --git a/src/librustc_builtin_macros/asm.rs b/src/librustc_builtin_macros/asm.rs index 675cc904a9f..7e5eca29aea 100644 --- a/src/librustc_builtin_macros/asm.rs +++ b/src/librustc_builtin_macros/asm.rs @@ -288,7 +288,12 @@ fn err_duplicate_option<'a>(p: &mut Parser<'a>, symbol: Symbol, span: Span) { .sess .span_diagnostic .struct_span_err(span, &format!("the `{}` option was already provided", symbol)); - err.span_suggestion(span, "remove this option", String::new(), Applicability::Unspecified); + err.span_suggestion( + span, + "remove this option", + String::new(), + Applicability::MachineApplicable, + ); err.emit(); } @@ -301,7 +306,11 @@ fn try_set_option<'a>( if !args.options.contains(option) { args.options |= option; } else { - err_duplicate_option(p, symbol, p.prev_token.span); + let mut span = p.prev_token.span; + if p.look_ahead(0, |t| t == &token::Comma) { + span = span.to(p.token.span); + } + err_duplicate_option(p, symbol, span); } } diff --git a/src/test/ui/asm/duplicate-options.fixed b/src/test/ui/asm/duplicate-options.fixed new file mode 100644 index 00000000000..f4672a50fd0 --- /dev/null +++ b/src/test/ui/asm/duplicate-options.fixed @@ -0,0 +1,26 @@ +// only-x86_64 +// run-rustfix + +#![feature(asm)] + +fn main() { + unsafe { + asm!("", options(nomem, )); + //~^ ERROR the `nomem` option was already provided + asm!("", options(att_syntax, )); + //~^ ERROR the `att_syntax` option was already provided + asm!("", options(nostack, att_syntax), options()); + //~^ ERROR the `nostack` option was already provided + asm!("", options(nostack, ), options(), options()); + //~^ ERROR the `nostack` option was already provided + //~| ERROR the `nostack` option was already provided + //~| ERROR the `nostack` option was already provided + asm!( + "", + options(nomem, noreturn), + options(att_syntax, ), //~ ERROR the `noreturn` option was already provided + options( nostack), //~ ERROR the `nomem` option was already provided + options(), //~ ERROR the `noreturn` option was already provided + ); + } +} diff --git a/src/test/ui/asm/duplicate-options.rs b/src/test/ui/asm/duplicate-options.rs index 34371b854f8..80292d7521a 100644 --- a/src/test/ui/asm/duplicate-options.rs +++ b/src/test/ui/asm/duplicate-options.rs @@ -1,4 +1,5 @@ // only-x86_64 +// run-rustfix #![feature(asm)] diff --git a/src/test/ui/asm/duplicate-options.stderr b/src/test/ui/asm/duplicate-options.stderr index 9aa699c4e76..46a966ddc86 100644 --- a/src/test/ui/asm/duplicate-options.stderr +++ b/src/test/ui/asm/duplicate-options.stderr @@ -1,53 +1,53 @@ error: the `nomem` option was already provided - --> $DIR/duplicate-options.rs:7:33 + --> $DIR/duplicate-options.rs:8:33 | LL | asm!("", options(nomem, nomem)); | ^^^^^ help: remove this option error: the `att_syntax` option was already provided - --> $DIR/duplicate-options.rs:9:38 + --> $DIR/duplicate-options.rs:10:38 | LL | asm!("", options(att_syntax, att_syntax)); | ^^^^^^^^^^ help: remove this option error: the `nostack` option was already provided - --> $DIR/duplicate-options.rs:11:56 + --> $DIR/duplicate-options.rs:12:56 | LL | asm!("", options(nostack, att_syntax), options(nostack)); | ^^^^^^^ help: remove this option error: the `nostack` option was already provided - --> $DIR/duplicate-options.rs:13:35 + --> $DIR/duplicate-options.rs:14:35 | LL | asm!("", options(nostack, nostack), options(nostack), options(nostack)); | ^^^^^^^ help: remove this option error: the `nostack` option was already provided - --> $DIR/duplicate-options.rs:13:53 + --> $DIR/duplicate-options.rs:14:53 | LL | asm!("", options(nostack, nostack), options(nostack), options(nostack)); | ^^^^^^^ help: remove this option error: the `nostack` option was already provided - --> $DIR/duplicate-options.rs:13:71 + --> $DIR/duplicate-options.rs:14:71 | LL | asm!("", options(nostack, nostack), options(nostack), options(nostack)); | ^^^^^^^ help: remove this option error: the `noreturn` option was already provided - --> $DIR/duplicate-options.rs:20:33 + --> $DIR/duplicate-options.rs:21:33 | LL | options(att_syntax, noreturn), | ^^^^^^^^ help: remove this option error: the `nomem` option was already provided - --> $DIR/duplicate-options.rs:21:21 + --> $DIR/duplicate-options.rs:22:21 | LL | options(nomem, nostack), - | ^^^^^ help: remove this option + | ^^^^^^ help: remove this option error: the `noreturn` option was already provided - --> $DIR/duplicate-options.rs:22:21 + --> $DIR/duplicate-options.rs:23:21 | LL | options(noreturn), | ^^^^^^^^ help: remove this option