]> git.lizzy.rs Git - rust.git/commitdiff
Fix invalid keyword order for function declarations
authorKen Matsui <26405363+ken-matsui@users.noreply.github.com>
Mon, 2 May 2022 09:14:43 +0000 (18:14 +0900)
committerKen Matsui <26405363+ken-matsui@users.noreply.github.com>
Mon, 2 May 2022 09:14:43 +0000 (18:14 +0900)
14 files changed:
compiler/rustc_parse/src/parser/item.rs
src/test/ui/async-await/no-async-const.stderr
src/test/ui/async-await/no-unsafe-async.stderr
src/test/ui/fn/keyword-order.rs [new file with mode: 0644]
src/test/ui/fn/keyword-order.stderr [new file with mode: 0644]
src/test/ui/parser/issues/issue-19398.stderr
src/test/ui/parser/issues/issue-87217-keyword-order/several-kw-jump.rs
src/test/ui/parser/issues/issue-87217-keyword-order/several-kw-jump.stderr
src/test/ui/parser/issues/issue-87217-keyword-order/wrong-async.rs
src/test/ui/parser/issues/issue-87217-keyword-order/wrong-async.stderr
src/test/ui/parser/issues/issue-87217-keyword-order/wrong-const.rs
src/test/ui/parser/issues/issue-87217-keyword-order/wrong-const.stderr
src/test/ui/parser/issues/issue-87217-keyword-order/wrong-unsafe.rs
src/test/ui/parser/issues/issue-87217-keyword-order/wrong-unsafe.stderr

index 10f1daf11295107540cd1d6d180741c3db06c49d..77a03428c166417048563860acae63db2ed63820 100644 (file)
@@ -1020,7 +1020,7 @@ fn parse_item_foreign_mod(
                                 &format!("`{}` must come before `{}`", invalid_qual, current_qual),
                                 format!("{} {}", invalid_qual, current_qual),
                                 Applicability::MachineApplicable,
-                            ).note("keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`");
+                            ).note("keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`");
                     }
                 }
                 Err(err)
@@ -2086,7 +2086,7 @@ enum WrongKw {
                                     &format!("`{misplaced_qual}` must come before `{current_qual}`"),
                                     format!("{misplaced_qual} {current_qual}"),
                                     Applicability::MachineApplicable,
-                                ).note("keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`");
+                                ).note("keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`");
                         }
                     }
                     // Recover incorrect visibility order such as `async pub`
index ae13b90c3cfc0bd33f7cd806337cb38e48eaf16f..a51dc88a4eded368247b823ca0be53a5537ee326 100644 (file)
@@ -7,7 +7,7 @@ LL | pub async const fn x() {}
    |     |     expected one of `extern`, `fn`, or `unsafe`
    |     help: `const` must come before `async`: `const async`
    |
-   = note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
+   = note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
 
 error: aborting due to previous error
 
index 0c362052501ed1ec8f61607876779a8bc03a8d31..f23d17d6bfa5795e8ad5b5afc4a2846bf2be875e 100644 (file)
@@ -12,7 +12,7 @@ LL |     unsafe async fn g() {}
 LL | }
    | - the item list ends here
    |
-   = note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
+   = note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
 
 error: expected one of `extern` or `fn`, found keyword `async`
   --> $DIR/no-unsafe-async.rs:11:8
@@ -23,7 +23,7 @@ LL | unsafe async fn f() {}
    | |      expected one of `extern` or `fn`
    | help: `async` must come before `unsafe`: `async unsafe`
    |
-   = note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
+   = note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/fn/keyword-order.rs b/src/test/ui/fn/keyword-order.rs
new file mode 100644 (file)
index 0000000..8a21db6
--- /dev/null
@@ -0,0 +1,6 @@
+// edition:2018
+
+default pub const async unsafe extern fn err() {} //~ ERROR `default` is not followed by an item
+//~^ ERROR expected item, found keyword `pub`
+
+pub default const async unsafe extern fn ok() {}
diff --git a/src/test/ui/fn/keyword-order.stderr b/src/test/ui/fn/keyword-order.stderr
new file mode 100644 (file)
index 0000000..d3b140c
--- /dev/null
@@ -0,0 +1,16 @@
+error: `default` is not followed by an item
+  --> $DIR/keyword-order.rs:3:1
+   |
+LL | default pub const async unsafe extern fn err() {}
+   | ^^^^^^^ the `default` qualifier
+   |
+   = note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
+
+error: expected item, found keyword `pub`
+  --> $DIR/keyword-order.rs:3:9
+   |
+LL | default pub const async unsafe extern fn err() {}
+   |         ^^^ expected item
+
+error: aborting due to 2 previous errors
+
index f9c3ca763f26ea5728103dad29d7f723d551b3fd..bbd85374b4bcfb9a0393ded136f72d2c4bc2dc54 100644 (file)
@@ -12,7 +12,7 @@ LL |
 LL | }
    | - the item list ends here
    |
-   = note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
+   = note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
 
 error: aborting due to previous error
 
index 86fdb78cce8aba23f39e4ce9d36c583e346d67ed..bbebc99e94b8236a280d78a37081eaf63917c663 100644 (file)
@@ -11,4 +11,4 @@
 //~| NOTE expected one of `extern` or `fn`
 //~| HELP `const` must come before `async unsafe`
 //~| SUGGESTION const async unsafe
-//~| NOTE keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
+//~| NOTE keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
index 65cce77be896bc6c0d1b359c4a84159be1ed6e14..f455caba158c77728c43d9ffd54ab37d50b64e4e 100644 (file)
@@ -7,7 +7,7 @@ LL | async unsafe const fn test() {}
    | |            expected one of `extern` or `fn`
    | help: `const` must come before `async unsafe`: `const async unsafe`
    |
-   = note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
+   = note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
 
 error: aborting due to previous error
 
index edfb330d6713a31e8602f190fedea7903a55cfaa..4ff4cf5c8ca8768e625084a6ca4babaad35bcfd8 100644 (file)
@@ -11,4 +11,4 @@
 //~| NOTE expected one of `extern` or `fn`
 //~| HELP `async` must come before `unsafe`
 //~| SUGGESTION async unsafe
-//~| NOTE keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
+//~| NOTE keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
index 3acd9e4400432b304a83dff28139dfc7f5afafaf..e9eb14bf00e77ecc5d988e38c6db7798b01be6b0 100644 (file)
@@ -7,7 +7,7 @@ LL | unsafe async fn test() {}
    | |      expected one of `extern` or `fn`
    | help: `async` must come before `unsafe`: `async unsafe`
    |
-   = note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
+   = note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
 
 error: aborting due to previous error
 
index abd692b80d54b1ad45a89852fd28b294a95367eb..2f5fbc513ee3658051aa788acfd35edd47e520ac 100644 (file)
@@ -11,4 +11,4 @@
 //~| NOTE expected one of `extern` or `fn`
 //~| HELP `const` must come before `unsafe`
 //~| SUGGESTION const unsafe
-//~| NOTE keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
+//~| NOTE keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
index 9a3e07b1e87f64638c5604b09ac1d7515a7cb470..0d2bc3472965f6c576a8764c3e821e1b016057ca 100644 (file)
@@ -7,7 +7,7 @@ LL | unsafe const fn test() {}
    | |      expected one of `extern` or `fn`
    | help: `const` must come before `unsafe`: `const unsafe`
    |
-   = note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
+   = note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
 
 error: aborting due to previous error
 
index 7f0761e99386a3c43a8f4a5c477327f94fc0831f..df2412e3e9b32e4b3e71b158eb059abbe50d4f6e 100644 (file)
@@ -11,4 +11,4 @@
 //~| NOTE expected `fn`
 //~| HELP `unsafe` must come before `extern`
 //~| SUGGESTION unsafe extern
-//~| NOTE keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
+//~| NOTE keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
index 395ee9fedbc0726d4b82b2384c333daeceeb9ec7..4224713ccb53af36e3fd62a64dfc6ba675937268 100644 (file)
@@ -7,7 +7,7 @@ LL | extern unsafe fn test() {}
    | |      expected `fn`
    | help: `unsafe` must come before `extern`: `unsafe extern`
    |
-   = note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern`
+   = note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
 
 error: aborting due to previous error