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

Commit b94b7e7

Browse files
committed
Make warning an error; use help instead of suggestion; clean up code
For some reason, the help message is now in a separate message, which adds a lot of noise. I would like to try to get it back to one message.
1 parent 7aaadb6 commit b94b7e7

File tree

3 files changed

+87
-71
lines changed

3 files changed

+87
-71
lines changed

src/librustc_builtin_macros/asm.rs

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

292-
fn warn_duplicate_option<'a>(p: &mut Parser<'a>, span: Span) {
293-
let mut warn = if let Ok(snippet) = p.sess.source_map().span_to_snippet(span) {
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) {
294294
p.sess
295295
.span_diagnostic
296-
.struct_span_warn(span, &format!("the `{}` option was already provided", snippet))
296+
.struct_span_err(span, &format!("the `{}` option was already provided", snippet))
297297
} else {
298-
p.sess.span_diagnostic.struct_span_warn(span, "this option was already provided")
298+
p.sess.span_diagnostic.struct_span_err(span, "this option was already provided")
299299
};
300-
warn.span_suggestion(
301-
span,
302-
"remove this option",
303-
String::new(),
304-
Applicability::MachineApplicable,
305-
);
306-
warn.emit();
300+
err.span_help(span, "remove this option");
301+
err.emit();
302+
}
303+
304+
fn try_set_option<'a>(p: &mut Parser<'a>, args: &mut AsmArgs, option: ast::InlineAsmOptions) {
305+
if !args.option_is_set(option) {
306+
args.options |= option;
307+
} else {
308+
err_duplicate_option(p, p.prev_token.span);
309+
}
307310
}
308311

309312
fn parse_options<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> Result<(), DiagnosticBuilder<'a>> {
@@ -313,48 +316,20 @@ fn parse_options<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> Result<(), Diagn
313316

314317
while !p.eat(&token::CloseDelim(token::DelimToken::Paren)) {
315318
if p.eat(&token::Ident(sym::pure, false)) {
316-
if !args.option_is_set(ast::InlineAsmOptions::PURE) {
317-
args.options |= ast::InlineAsmOptions::PURE;
318-
} else {
319-
warn_duplicate_option(p, p.prev_token.span);
320-
}
319+
try_set_option(p, args, ast::InlineAsmOptions::PURE);
321320
} else if p.eat(&token::Ident(sym::nomem, false)) {
322-
if !args.option_is_set(ast::InlineAsmOptions::NOMEM) {
323-
args.options |= ast::InlineAsmOptions::NOMEM;
324-
} else {
325-
warn_duplicate_option(p, p.prev_token.span);
326-
}
321+
try_set_option(p, args, ast::InlineAsmOptions::NOMEM);
327322
} else if p.eat(&token::Ident(sym::readonly, false)) {
328-
if !args.option_is_set(ast::InlineAsmOptions::READONLY) {
329-
args.options |= ast::InlineAsmOptions::READONLY;
330-
} else {
331-
warn_duplicate_option(p, p.prev_token.span);
332-
}
323+
try_set_option(p, args, ast::InlineAsmOptions::READONLY);
333324
} else if p.eat(&token::Ident(sym::preserves_flags, false)) {
334-
if !args.option_is_set(ast::InlineAsmOptions::PRESERVES_FLAGS) {
335-
args.options |= ast::InlineAsmOptions::PRESERVES_FLAGS;
336-
} else {
337-
warn_duplicate_option(p, p.prev_token.span);
338-
}
325+
try_set_option(p, args, ast::InlineAsmOptions::PRESERVES_FLAGS);
339326
} else if p.eat(&token::Ident(sym::noreturn, false)) {
340-
if !args.option_is_set(ast::InlineAsmOptions::NORETURN) {
341-
args.options |= ast::InlineAsmOptions::NORETURN;
342-
} else {
343-
warn_duplicate_option(p, p.prev_token.span);
344-
}
327+
try_set_option(p, args, ast::InlineAsmOptions::NORETURN);
345328
} else if p.eat(&token::Ident(sym::nostack, false)) {
346-
if !args.option_is_set(ast::InlineAsmOptions::NOSTACK) {
347-
args.options |= ast::InlineAsmOptions::NOSTACK;
348-
} else {
349-
warn_duplicate_option(p, p.prev_token.span);
350-
}
329+
try_set_option(p, args, ast::InlineAsmOptions::NOSTACK);
351330
} else {
352331
p.expect(&token::Ident(sym::att_syntax, false))?;
353-
if !args.option_is_set(ast::InlineAsmOptions::ATT_SYNTAX) {
354-
args.options |= ast::InlineAsmOptions::ATT_SYNTAX;
355-
} else {
356-
warn_duplicate_option(p, p.prev_token.span);
357-
}
332+
try_set_option(p, args, ast::InlineAsmOptions::ATT_SYNTAX);
358333
}
359334

360335
// Allow trailing commas

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
// only-x86_64
2-
// build-pass
32

43
#![feature(asm)]
54

65
fn main() {
76
unsafe {
87
asm!("", options(nomem, nomem));
9-
//~^ WARNING the `nomem` option was already provided
8+
//~^ ERROR the `nomem` option was already provided
9+
//~| HELP remove this option
1010
asm!("", options(att_syntax, att_syntax));
11-
//~^ WARNING the `att_syntax` option was already provided
11+
//~^ ERROR the `att_syntax` option was already provided
12+
//~| HELP remove this option
1213
asm!("", options(nostack, att_syntax), options(nostack));
13-
//~^ WARNING the `nostack` option was already provided
14+
//~^ ERROR the `nostack` option was already provided
15+
//~| HELP remove this option
1416
asm!("", options(nostack, nostack), options(nostack), options(nostack));
15-
//~^ WARNING the `nostack` option was already provided
16-
//~| WARNING the `nostack` option was already provided
17-
//~| WARNING the `nostack` option was already provided
17+
//~^ ERROR the `nostack` option was already provided
18+
//~| HELP remove this option
19+
//~| ERROR the `nostack` option was already provided
20+
//~| HELP remove this option
21+
//~| ERROR the `nostack` option was already provided
22+
//~| HELP remove this option
1823
}
1924
}
Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,74 @@
1-
warning: the `nomem` option was already provided
2-
--> $DIR/duplicate-options.rs:8:33
1+
error: the `nomem` option was already provided
2+
--> $DIR/duplicate-options.rs:7:33
33
|
44
LL | asm!("", options(nomem, nomem));
5-
| ^^^^^ help: remove this option
5+
| ^^^^^
6+
|
7+
help: remove this option
8+
--> $DIR/duplicate-options.rs:7:33
9+
|
10+
LL | asm!("", options(nomem, nomem));
11+
| ^^^^^
612

7-
warning: the `att_syntax` option was already provided
13+
error: the `att_syntax` option was already provided
14+
--> $DIR/duplicate-options.rs:10:38
15+
|
16+
LL | asm!("", options(att_syntax, att_syntax));
17+
| ^^^^^^^^^^
18+
|
19+
help: remove this option
820
--> $DIR/duplicate-options.rs:10:38
921
|
1022
LL | asm!("", options(att_syntax, att_syntax));
11-
| ^^^^^^^^^^ help: remove this option
23+
| ^^^^^^^^^^
1224

13-
warning: the `nostack` option was already provided
14-
--> $DIR/duplicate-options.rs:12:56
25+
error: the `nostack` option was already provided
26+
--> $DIR/duplicate-options.rs:13:56
27+
|
28+
LL | asm!("", options(nostack, att_syntax), options(nostack));
29+
| ^^^^^^^
30+
|
31+
help: remove this option
32+
--> $DIR/duplicate-options.rs:13:56
1533
|
1634
LL | asm!("", options(nostack, att_syntax), options(nostack));
17-
| ^^^^^^^ help: remove this option
35+
| ^^^^^^^
1836

19-
warning: the `nostack` option was already provided
20-
--> $DIR/duplicate-options.rs:14:35
37+
error: the `nostack` option was already provided
38+
--> $DIR/duplicate-options.rs:16:35
2139
|
2240
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack));
23-
| ^^^^^^^ help: remove this option
41+
| ^^^^^^^
42+
|
43+
help: remove this option
44+
--> $DIR/duplicate-options.rs:16:35
45+
|
46+
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack));
47+
| ^^^^^^^
2448

25-
warning: the `nostack` option was already provided
26-
--> $DIR/duplicate-options.rs:14:53
49+
error: the `nostack` option was already provided
50+
--> $DIR/duplicate-options.rs:16:53
2751
|
2852
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack));
29-
| ^^^^^^^ help: remove this option
53+
| ^^^^^^^
54+
|
55+
help: remove this option
56+
--> $DIR/duplicate-options.rs:16:53
57+
|
58+
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack));
59+
| ^^^^^^^
3060

31-
warning: the `nostack` option was already provided
32-
--> $DIR/duplicate-options.rs:14:71
61+
error: the `nostack` option was already provided
62+
--> $DIR/duplicate-options.rs:16:71
63+
|
64+
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack));
65+
| ^^^^^^^
66+
|
67+
help: remove this option
68+
--> $DIR/duplicate-options.rs:16:71
3369
|
3470
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack));
35-
| ^^^^^^^ help: remove this option
71+
| ^^^^^^^
3672

37-
warning: 6 warnings emitted
73+
error: aborting due to 6 previous errors
3874

0 commit comments

Comments
 (0)