Skip to content

Commit 4ba6697

Browse files
committed
Make suggestion machine-applicable
1 parent f4dfc61 commit 4ba6697

File tree

4 files changed

+48
-12
lines changed

4 files changed

+48
-12
lines changed

src/librustc_builtin_macros/asm.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,12 @@ fn err_duplicate_option<'a>(p: &mut Parser<'a>, symbol: Symbol, span: Span) {
288288
.sess
289289
.span_diagnostic
290290
.struct_span_err(span, &format!("the `{}` option was already provided", symbol));
291-
err.span_suggestion(span, "remove this option", String::new(), Applicability::Unspecified);
291+
err.span_suggestion(
292+
span,
293+
"remove this option",
294+
String::new(),
295+
Applicability::MachineApplicable,
296+
);
292297
err.emit();
293298
}
294299

@@ -301,7 +306,11 @@ fn try_set_option<'a>(
301306
if !args.options.contains(option) {
302307
args.options |= option;
303308
} else {
304-
err_duplicate_option(p, symbol, p.prev_token.span);
309+
let mut span = p.prev_token.span;
310+
if p.look_ahead(0, |t| t == &token::Comma) {
311+
span = span.to(p.token.span);
312+
}
313+
err_duplicate_option(p, symbol, span);
305314
}
306315
}
307316

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// only-x86_64
2+
// run-rustfix
3+
4+
#![feature(asm)]
5+
6+
fn main() {
7+
unsafe {
8+
asm!("", options(nomem, ));
9+
//~^ ERROR the `nomem` option was already provided
10+
asm!("", options(att_syntax, ));
11+
//~^ ERROR the `att_syntax` option was already provided
12+
asm!("", options(nostack, att_syntax), options());
13+
//~^ ERROR the `nostack` option was already provided
14+
asm!("", options(nostack, ), options(), options());
15+
//~^ ERROR the `nostack` option was already provided
16+
//~| ERROR the `nostack` option was already provided
17+
//~| ERROR the `nostack` option was already provided
18+
asm!(
19+
"",
20+
options(nomem, noreturn),
21+
options(att_syntax, ), //~ ERROR the `noreturn` option was already provided
22+
options( nostack), //~ ERROR the `nomem` option was already provided
23+
options(), //~ ERROR the `noreturn` option was already provided
24+
);
25+
}
26+
}

src/test/ui/asm/duplicate-options.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// only-x86_64
2+
// run-rustfix
23

34
#![feature(asm)]
45

src/test/ui/asm/duplicate-options.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
error: the `nomem` option was already provided
2-
--> $DIR/duplicate-options.rs:7:33
2+
--> $DIR/duplicate-options.rs:8:33
33
|
44
LL | asm!("", options(nomem, nomem));
55
| ^^^^^ help: remove this option
66

77
error: the `att_syntax` option was already provided
8-
--> $DIR/duplicate-options.rs:9:38
8+
--> $DIR/duplicate-options.rs:10:38
99
|
1010
LL | asm!("", options(att_syntax, att_syntax));
1111
| ^^^^^^^^^^ help: remove this option
1212

1313
error: the `nostack` option was already provided
14-
--> $DIR/duplicate-options.rs:11:56
14+
--> $DIR/duplicate-options.rs:12:56
1515
|
1616
LL | asm!("", options(nostack, att_syntax), options(nostack));
1717
| ^^^^^^^ help: remove this option
1818

1919
error: the `nostack` option was already provided
20-
--> $DIR/duplicate-options.rs:13:35
20+
--> $DIR/duplicate-options.rs:14:35
2121
|
2222
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack));
2323
| ^^^^^^^ help: remove this option
2424

2525
error: the `nostack` option was already provided
26-
--> $DIR/duplicate-options.rs:13:53
26+
--> $DIR/duplicate-options.rs:14:53
2727
|
2828
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack));
2929
| ^^^^^^^ help: remove this option
3030

3131
error: the `nostack` option was already provided
32-
--> $DIR/duplicate-options.rs:13:71
32+
--> $DIR/duplicate-options.rs:14:71
3333
|
3434
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack));
3535
| ^^^^^^^ help: remove this option
3636

3737
error: the `noreturn` option was already provided
38-
--> $DIR/duplicate-options.rs:20:33
38+
--> $DIR/duplicate-options.rs:21:33
3939
|
4040
LL | options(att_syntax, noreturn),
4141
| ^^^^^^^^ help: remove this option
4242

4343
error: the `nomem` option was already provided
44-
--> $DIR/duplicate-options.rs:21:21
44+
--> $DIR/duplicate-options.rs:22:21
4545
|
4646
LL | options(nomem, nostack),
47-
| ^^^^^ help: remove this option
47+
| ^^^^^^ help: remove this option
4848

4949
error: the `noreturn` option was already provided
50-
--> $DIR/duplicate-options.rs:22:21
50+
--> $DIR/duplicate-options.rs:23:21
5151
|
5252
LL | options(noreturn),
5353
| ^^^^^^^^ help: remove this option

0 commit comments

Comments
 (0)