]> git.lizzy.rs Git - rust.git/commitdiff
Make suggestion machine-applicable
authorCamelid <camelidcamel@gmail.com>
Tue, 16 Jun 2020 19:32:13 +0000 (12:32 -0700)
committerCamelid <camelidcamel@gmail.com>
Sat, 20 Jun 2020 18:12:43 +0000 (11:12 -0700)
src/librustc_builtin_macros/asm.rs
src/test/ui/asm/duplicate-options.fixed [new file with mode: 0644]
src/test/ui/asm/duplicate-options.rs
src/test/ui/asm/duplicate-options.stderr

index 675cc904a9f04ac5d8179613c81ebec684de25ee..7e5eca29aeada0352be0555bb12bcbe05113400a 100644 (file)
@@ -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 (file)
index 0000000..f4672a5
--- /dev/null
@@ -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
+        );
+    }
+}
index 34371b854f8e202854c16acf64ede73df73c3da6..80292d7521a9a4f7f812495003241d8bbb34d32a 100644 (file)
@@ -1,4 +1,5 @@
 // only-x86_64
+// run-rustfix
 
 #![feature(asm)]
 
index 9aa699c4e76e8c1cfcfbf6d7500c52c5eea3eebb..46a966ddc8606a584f97a539d42e08e0641814c3 100644 (file)
@@ -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