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.
This commit is contained in:
parent
7aaadb69e4
commit
b94b7e7f1b
@ -289,21 +289,24 @@ fn parse_args<'a>(
|
|||||||
Ok(args)
|
Ok(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn warn_duplicate_option<'a>(p: &mut Parser<'a>, span: Span) {
|
fn err_duplicate_option<'a>(p: &mut Parser<'a>, span: Span) {
|
||||||
let mut warn = if let Ok(snippet) = p.sess.source_map().span_to_snippet(span) {
|
let mut err = if let Ok(snippet) = p.sess.source_map().span_to_snippet(span) {
|
||||||
p.sess
|
p.sess
|
||||||
.span_diagnostic
|
.span_diagnostic
|
||||||
.struct_span_warn(span, &format!("the `{}` option was already provided", snippet))
|
.struct_span_err(span, &format!("the `{}` option was already provided", snippet))
|
||||||
} else {
|
} else {
|
||||||
p.sess.span_diagnostic.struct_span_warn(span, "this option was already provided")
|
p.sess.span_diagnostic.struct_span_err(span, "this option was already provided")
|
||||||
};
|
};
|
||||||
warn.span_suggestion(
|
err.span_help(span, "remove this option");
|
||||||
span,
|
err.emit();
|
||||||
"remove this option",
|
}
|
||||||
String::new(),
|
|
||||||
Applicability::MachineApplicable,
|
fn try_set_option<'a>(p: &mut Parser<'a>, args: &mut AsmArgs, option: ast::InlineAsmOptions) {
|
||||||
);
|
if !args.option_is_set(option) {
|
||||||
warn.emit();
|
args.options |= option;
|
||||||
|
} else {
|
||||||
|
err_duplicate_option(p, p.prev_token.span);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_options<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> Result<(), DiagnosticBuilder<'a>> {
|
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
|
|||||||
|
|
||||||
while !p.eat(&token::CloseDelim(token::DelimToken::Paren)) {
|
while !p.eat(&token::CloseDelim(token::DelimToken::Paren)) {
|
||||||
if p.eat(&token::Ident(sym::pure, false)) {
|
if p.eat(&token::Ident(sym::pure, false)) {
|
||||||
if !args.option_is_set(ast::InlineAsmOptions::PURE) {
|
try_set_option(p, args, ast::InlineAsmOptions::PURE);
|
||||||
args.options |= ast::InlineAsmOptions::PURE;
|
|
||||||
} else {
|
|
||||||
warn_duplicate_option(p, p.prev_token.span);
|
|
||||||
}
|
|
||||||
} else if p.eat(&token::Ident(sym::nomem, false)) {
|
} else if p.eat(&token::Ident(sym::nomem, false)) {
|
||||||
if !args.option_is_set(ast::InlineAsmOptions::NOMEM) {
|
try_set_option(p, args, ast::InlineAsmOptions::NOMEM);
|
||||||
args.options |= ast::InlineAsmOptions::NOMEM;
|
|
||||||
} else {
|
|
||||||
warn_duplicate_option(p, p.prev_token.span);
|
|
||||||
}
|
|
||||||
} else if p.eat(&token::Ident(sym::readonly, false)) {
|
} else if p.eat(&token::Ident(sym::readonly, false)) {
|
||||||
if !args.option_is_set(ast::InlineAsmOptions::READONLY) {
|
try_set_option(p, args, ast::InlineAsmOptions::READONLY);
|
||||||
args.options |= ast::InlineAsmOptions::READONLY;
|
|
||||||
} else {
|
|
||||||
warn_duplicate_option(p, p.prev_token.span);
|
|
||||||
}
|
|
||||||
} else if p.eat(&token::Ident(sym::preserves_flags, false)) {
|
} else if p.eat(&token::Ident(sym::preserves_flags, false)) {
|
||||||
if !args.option_is_set(ast::InlineAsmOptions::PRESERVES_FLAGS) {
|
try_set_option(p, args, ast::InlineAsmOptions::PRESERVES_FLAGS);
|
||||||
args.options |= ast::InlineAsmOptions::PRESERVES_FLAGS;
|
|
||||||
} else {
|
|
||||||
warn_duplicate_option(p, p.prev_token.span);
|
|
||||||
}
|
|
||||||
} else if p.eat(&token::Ident(sym::noreturn, false)) {
|
} else if p.eat(&token::Ident(sym::noreturn, false)) {
|
||||||
if !args.option_is_set(ast::InlineAsmOptions::NORETURN) {
|
try_set_option(p, args, ast::InlineAsmOptions::NORETURN);
|
||||||
args.options |= ast::InlineAsmOptions::NORETURN;
|
|
||||||
} else {
|
|
||||||
warn_duplicate_option(p, p.prev_token.span);
|
|
||||||
}
|
|
||||||
} else if p.eat(&token::Ident(sym::nostack, false)) {
|
} else if p.eat(&token::Ident(sym::nostack, false)) {
|
||||||
if !args.option_is_set(ast::InlineAsmOptions::NOSTACK) {
|
try_set_option(p, args, ast::InlineAsmOptions::NOSTACK);
|
||||||
args.options |= ast::InlineAsmOptions::NOSTACK;
|
|
||||||
} else {
|
|
||||||
warn_duplicate_option(p, p.prev_token.span);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
p.expect(&token::Ident(sym::att_syntax, false))?;
|
p.expect(&token::Ident(sym::att_syntax, false))?;
|
||||||
if !args.option_is_set(ast::InlineAsmOptions::ATT_SYNTAX) {
|
try_set_option(p, args, ast::InlineAsmOptions::ATT_SYNTAX);
|
||||||
args.options |= ast::InlineAsmOptions::ATT_SYNTAX;
|
|
||||||
} else {
|
|
||||||
warn_duplicate_option(p, p.prev_token.span);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow trailing commas
|
// Allow trailing commas
|
||||||
|
@ -1,19 +1,24 @@
|
|||||||
// only-x86_64
|
// only-x86_64
|
||||||
// build-pass
|
|
||||||
|
|
||||||
#![feature(asm)]
|
#![feature(asm)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!("", options(nomem, nomem));
|
asm!("", options(nomem, nomem));
|
||||||
//~^ WARNING the `nomem` option was already provided
|
//~^ ERROR the `nomem` option was already provided
|
||||||
|
//~| HELP remove this option
|
||||||
asm!("", options(att_syntax, att_syntax));
|
asm!("", options(att_syntax, att_syntax));
|
||||||
//~^ WARNING the `att_syntax` option was already provided
|
//~^ ERROR the `att_syntax` option was already provided
|
||||||
|
//~| HELP remove this option
|
||||||
asm!("", options(nostack, att_syntax), options(nostack));
|
asm!("", options(nostack, att_syntax), options(nostack));
|
||||||
//~^ WARNING the `nostack` option was already provided
|
//~^ ERROR the `nostack` option was already provided
|
||||||
|
//~| HELP remove this option
|
||||||
asm!("", options(nostack, nostack), options(nostack), options(nostack));
|
asm!("", options(nostack, nostack), options(nostack), options(nostack));
|
||||||
//~^ WARNING the `nostack` option was already provided
|
//~^ ERROR the `nostack` option was already provided
|
||||||
//~| WARNING the `nostack` option was already provided
|
//~| HELP remove this option
|
||||||
//~| WARNING the `nostack` option was already provided
|
//~| ERROR the `nostack` option was already provided
|
||||||
|
//~| HELP remove this option
|
||||||
|
//~| ERROR the `nostack` option was already provided
|
||||||
|
//~| HELP remove this option
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,38 +1,74 @@
|
|||||||
warning: the `nomem` option was already provided
|
error: the `nomem` option was already provided
|
||||||
--> $DIR/duplicate-options.rs:8:33
|
--> $DIR/duplicate-options.rs:7:33
|
||||||
|
|
|
|
||||||
LL | asm!("", options(nomem, nomem));
|
LL | asm!("", options(nomem, nomem));
|
||||||
| ^^^^^ help: remove this option
|
| ^^^^^
|
||||||
|
|
|
||||||
|
help: remove this option
|
||||||
|
--> $DIR/duplicate-options.rs:7:33
|
||||||
|
|
|
||||||
|
LL | asm!("", options(nomem, nomem));
|
||||||
|
| ^^^^^
|
||||||
|
|
||||||
warning: the `att_syntax` option was already provided
|
error: the `att_syntax` option was already provided
|
||||||
--> $DIR/duplicate-options.rs:10:38
|
--> $DIR/duplicate-options.rs:10:38
|
||||||
|
|
|
|
||||||
LL | asm!("", options(att_syntax, att_syntax));
|
LL | asm!("", options(att_syntax, att_syntax));
|
||||||
| ^^^^^^^^^^ help: remove this option
|
| ^^^^^^^^^^
|
||||||
|
|
|
||||||
|
help: remove this option
|
||||||
|
--> $DIR/duplicate-options.rs:10:38
|
||||||
|
|
|
||||||
|
LL | asm!("", options(att_syntax, att_syntax));
|
||||||
|
| ^^^^^^^^^^
|
||||||
|
|
||||||
warning: the `nostack` option was already provided
|
error: the `nostack` option was already provided
|
||||||
--> $DIR/duplicate-options.rs:12:56
|
--> $DIR/duplicate-options.rs:13:56
|
||||||
|
|
|
|
||||||
LL | asm!("", options(nostack, att_syntax), options(nostack));
|
LL | asm!("", options(nostack, att_syntax), options(nostack));
|
||||||
| ^^^^^^^ help: remove this option
|
| ^^^^^^^
|
||||||
|
|
|
||||||
|
help: remove this option
|
||||||
|
--> $DIR/duplicate-options.rs:13:56
|
||||||
|
|
|
||||||
|
LL | asm!("", options(nostack, att_syntax), options(nostack));
|
||||||
|
| ^^^^^^^
|
||||||
|
|
||||||
warning: the `nostack` option was already provided
|
error: the `nostack` option was already provided
|
||||||
--> $DIR/duplicate-options.rs:14:35
|
--> $DIR/duplicate-options.rs:16:35
|
||||||
|
|
|
|
||||||
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack));
|
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack));
|
||||||
| ^^^^^^^ help: remove this option
|
| ^^^^^^^
|
||||||
|
|
|
||||||
warning: the `nostack` option was already provided
|
help: remove this option
|
||||||
--> $DIR/duplicate-options.rs:14:53
|
--> $DIR/duplicate-options.rs:16:35
|
||||||
|
|
|
|
||||||
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack));
|
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack));
|
||||||
| ^^^^^^^ help: remove this option
|
| ^^^^^^^
|
||||||
|
|
||||||
warning: the `nostack` option was already provided
|
error: the `nostack` option was already provided
|
||||||
--> $DIR/duplicate-options.rs:14:71
|
--> $DIR/duplicate-options.rs:16:53
|
||||||
|
|
|
|
||||||
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack));
|
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack));
|
||||||
| ^^^^^^^ help: remove this option
|
| ^^^^^^^
|
||||||
|
|
|
||||||
|
help: remove this option
|
||||||
|
--> $DIR/duplicate-options.rs:16:53
|
||||||
|
|
|
||||||
|
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack));
|
||||||
|
| ^^^^^^^
|
||||||
|
|
||||||
warning: 6 warnings emitted
|
error: the `nostack` option was already provided
|
||||||
|
--> $DIR/duplicate-options.rs:16:71
|
||||||
|
|
|
||||||
|
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack));
|
||||||
|
| ^^^^^^^
|
||||||
|
|
|
||||||
|
help: remove this option
|
||||||
|
--> $DIR/duplicate-options.rs:16:71
|
||||||
|
|
|
||||||
|
LL | asm!("", options(nostack, nostack), options(nostack), options(nostack));
|
||||||
|
| ^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user