]> git.lizzy.rs Git - rust.git/commitdiff
Make warning an error; use help instead of suggestion; clean up code
authorCamelid <camelidcamel@gmail.com>
Sun, 14 Jun 2020 20:38:09 +0000 (13:38 -0700)
committerCamelid <camelidcamel@gmail.com>
Sat, 20 Jun 2020 18:12:42 +0000 (11:12 -0700)
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.

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

index b5641fdf2ab0fe45b77cc22fcf917f7e105eadf0..922a06bae93e497e83e1fd3bc8d2f7803fdfdc5b 100644 (file)
@@ -289,21 +289,24 @@ fn parse_args<'a>(
     Ok(args)
 }
 
-fn warn_duplicate_option<'a>(p: &mut Parser<'a>, span: Span) {
-    let mut warn = if let Ok(snippet) = p.sess.source_map().span_to_snippet(span) {
+fn err_duplicate_option<'a>(p: &mut Parser<'a>, span: Span) {
+    let mut err = if let Ok(snippet) = p.sess.source_map().span_to_snippet(span) {
         p.sess
             .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 {
-        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(
-        span,
-        "remove this option",
-        String::new(),
-        Applicability::MachineApplicable,
-    );
-    warn.emit();
+    err.span_help(span, "remove this option");
+    err.emit();
+}
+
+fn try_set_option<'a>(p: &mut Parser<'a>, args: &mut AsmArgs, option: ast::InlineAsmOptions) {
+    if !args.option_is_set(option) {
+        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>> {
@@ -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)) {
         if p.eat(&token::Ident(sym::pure, false)) {
-            if !args.option_is_set(ast::InlineAsmOptions::PURE) {
-                args.options |= ast::InlineAsmOptions::PURE;
-            } else {
-                warn_duplicate_option(p, p.prev_token.span);
-            }
+            try_set_option(p, args, ast::InlineAsmOptions::PURE);
         } else if p.eat(&token::Ident(sym::nomem, false)) {
-            if !args.option_is_set(ast::InlineAsmOptions::NOMEM) {
-                args.options |= ast::InlineAsmOptions::NOMEM;
-            } else {
-                warn_duplicate_option(p, p.prev_token.span);
-            }
+            try_set_option(p, args, ast::InlineAsmOptions::NOMEM);
         } else if p.eat(&token::Ident(sym::readonly, false)) {
-            if !args.option_is_set(ast::InlineAsmOptions::READONLY) {
-                args.options |= ast::InlineAsmOptions::READONLY;
-            } else {
-                warn_duplicate_option(p, p.prev_token.span);
-            }
+            try_set_option(p, args, ast::InlineAsmOptions::READONLY);
         } else if p.eat(&token::Ident(sym::preserves_flags, false)) {
-            if !args.option_is_set(ast::InlineAsmOptions::PRESERVES_FLAGS) {
-                args.options |= ast::InlineAsmOptions::PRESERVES_FLAGS;
-            } else {
-                warn_duplicate_option(p, p.prev_token.span);
-            }
+            try_set_option(p, args, ast::InlineAsmOptions::PRESERVES_FLAGS);
         } else if p.eat(&token::Ident(sym::noreturn, false)) {
-            if !args.option_is_set(ast::InlineAsmOptions::NORETURN) {
-                args.options |= ast::InlineAsmOptions::NORETURN;
-            } else {
-                warn_duplicate_option(p, p.prev_token.span);
-            }
+            try_set_option(p, args, ast::InlineAsmOptions::NORETURN);
         } else if p.eat(&token::Ident(sym::nostack, false)) {
-            if !args.option_is_set(ast::InlineAsmOptions::NOSTACK) {
-                args.options |= ast::InlineAsmOptions::NOSTACK;
-            } else {
-                warn_duplicate_option(p, p.prev_token.span);
-            }
+            try_set_option(p, args, ast::InlineAsmOptions::NOSTACK);
         } else {
             p.expect(&token::Ident(sym::att_syntax, false))?;
-            if !args.option_is_set(ast::InlineAsmOptions::ATT_SYNTAX) {
-                args.options |= ast::InlineAsmOptions::ATT_SYNTAX;
-            } else {
-                warn_duplicate_option(p, p.prev_token.span);
-            }
+            try_set_option(p, args, ast::InlineAsmOptions::ATT_SYNTAX);
         }
 
         // Allow trailing commas
index 9c447451511b4864402668f5c7ed96fa14a629fe..e412932fa7ebe717e5870b1111a75acf560f9baf 100644 (file)
@@ -1,19 +1,24 @@
 // only-x86_64
-// build-pass
 
 #![feature(asm)]
 
 fn main() {
     unsafe {
         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));
-        //~^ 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));
-        //~^ 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));
-        //~^ WARNING the `nostack` option was already provided
-        //~| WARNING the `nostack` option was already provided
-        //~| 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
+        //~| ERROR the `nostack` option was already provided
+        //~| HELP remove this option
     }
 }
index 113aca8da900fad77218ba314f63f6795c6724cc..accfdef474bb9aa0d504beaab207cc8c9879f751 100644 (file)
@@ -1,38 +1,74 @@
-warning: the `nomem` option was already provided
-  --> $DIR/duplicate-options.rs:8:33
+error: the `nomem` option was already provided
+  --> $DIR/duplicate-options.rs:7:33
    |
 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
+   |
+LL |         asm!("", options(att_syntax, att_syntax));
+   |                                      ^^^^^^^^^^
+   |
+help: remove this option
   --> $DIR/duplicate-options.rs:10:38
    |
 LL |         asm!("", options(att_syntax, att_syntax));
-   |                                      ^^^^^^^^^^ help: remove this option
+   |                                      ^^^^^^^^^^
 
-warning: the `nostack` option was already provided
-  --> $DIR/duplicate-options.rs:12:56
+error: the `nostack` option was already provided
+  --> $DIR/duplicate-options.rs:13:56
+   |
+LL |         asm!("", options(nostack, att_syntax), options(nostack));
+   |                                                        ^^^^^^^
+   |
+help: remove this option
+  --> $DIR/duplicate-options.rs:13:56
    |
 LL |         asm!("", options(nostack, att_syntax), options(nostack));
-   |                                                        ^^^^^^^ help: remove this option
+   |                                                        ^^^^^^^
 
-warning: the `nostack` option was already provided
-  --> $DIR/duplicate-options.rs:14:35
+error: the `nostack` option was already provided
+  --> $DIR/duplicate-options.rs:16:35
    |
 LL |         asm!("", options(nostack, nostack), options(nostack), options(nostack));
-   |                                   ^^^^^^^ help: remove this option
+   |                                   ^^^^^^^
+   |
+help: remove this option
+  --> $DIR/duplicate-options.rs:16:35
+   |
+LL |         asm!("", options(nostack, nostack), options(nostack), options(nostack));
+   |                                   ^^^^^^^
 
-warning: the `nostack` option was already provided
-  --> $DIR/duplicate-options.rs:14:53
+error: the `nostack` option was already provided
+  --> $DIR/duplicate-options.rs:16:53
    |
 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: the `nostack` option was already provided
-  --> $DIR/duplicate-options.rs:14:71
+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));
-   |                                                                       ^^^^^^^ help: remove this option
+   |                                                                       ^^^^^^^
 
-warning: 6 warnings emitted
+error: aborting due to 6 previous errors