diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-12-18 08:16:25 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-18 08:16:25 +0100 |
| commit | 54e7946d0fde56ea25b331df8d971bed0d232cac (patch) | |
| tree | edc8902c45141c72da3566abacd80c96f84eebbf /src | |
| parent | dde825db464b08d6f572766579dfb629b837368c (diff) | |
| parent | be33ca7d5b9c79a649ff4c38e0d351df326ff93c (diff) | |
| download | rust-54e7946d0fde56ea25b331df8d971bed0d232cac.tar.gz rust-54e7946d0fde56ea25b331df8d971bed0d232cac.zip | |
Rollup merge of #87901 - poliorcetics:pub-pub-pub, r=jackh726
Fix suggestion of additional `pub` when using `pub pub fn ...` Fix #87694. Marked as draft to start with because I want to explore doing the same fix for `const const fn` and other repeated-but-valid keywords. `@rustbot` label A-diagnostics D-invalid-suggestion T-compiler
Diffstat (limited to 'src')
8 files changed, 64 insertions, 15 deletions
diff --git a/src/test/ui/parser/duplicate-visibility.rs b/src/test/ui/parser/duplicate-visibility.rs index 87ba230eab5..32aeee29472 100644 --- a/src/test/ui/parser/duplicate-visibility.rs +++ b/src/test/ui/parser/duplicate-visibility.rs @@ -1,6 +1,9 @@ fn main() {} -extern "C" { +extern "C" { //~ NOTE while parsing this item list starting here pub pub fn foo(); //~^ ERROR expected one of `(`, `async`, `const`, `default`, `extern`, `fn`, `pub`, `unsafe`, or `use`, found keyword `pub` -} + //~| NOTE expected one of 9 possible tokens + //~| HELP there is already a visibility modifier, remove one + //~| NOTE explicit visibility first seen here +} //~ NOTE the item list ends here diff --git a/src/test/ui/parser/duplicate-visibility.stderr b/src/test/ui/parser/duplicate-visibility.stderr index d9815fc7395..97144ac2f64 100644 --- a/src/test/ui/parser/duplicate-visibility.stderr +++ b/src/test/ui/parser/duplicate-visibility.stderr @@ -7,10 +7,16 @@ LL | pub pub fn foo(); | ^^^ | | | expected one of 9 possible tokens - | help: visibility `pub` must come before `pub pub`: `pub pub pub` -LL | + | help: there is already a visibility modifier, remove one +... LL | } | - the item list ends here + | +note: explicit visibility first seen here + --> $DIR/duplicate-visibility.rs:4:5 + | +LL | pub pub fn foo(); + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/parser/issue-87694-duplicated-pub.rs b/src/test/ui/parser/issue-87694-duplicated-pub.rs new file mode 100644 index 00000000000..e3ea61dc4ad --- /dev/null +++ b/src/test/ui/parser/issue-87694-duplicated-pub.rs @@ -0,0 +1,5 @@ +pub const pub fn test() {} +//~^ ERROR expected one of `async`, `extern`, `fn`, or `unsafe`, found keyword `pub` +//~| NOTE expected one of `async`, `extern`, `fn`, or `unsafe` +//~| HELP there is already a visibility modifier, remove one +//~| NOTE explicit visibility first seen here diff --git a/src/test/ui/parser/issue-87694-duplicated-pub.stderr b/src/test/ui/parser/issue-87694-duplicated-pub.stderr new file mode 100644 index 00000000000..8d242bc9de5 --- /dev/null +++ b/src/test/ui/parser/issue-87694-duplicated-pub.stderr @@ -0,0 +1,17 @@ +error: expected one of `async`, `extern`, `fn`, or `unsafe`, found keyword `pub` + --> $DIR/issue-87694-duplicated-pub.rs:1:11 + | +LL | pub const pub fn test() {} + | ^^^ + | | + | expected one of `async`, `extern`, `fn`, or `unsafe` + | help: there is already a visibility modifier, remove one + | +note: explicit visibility first seen here + --> $DIR/issue-87694-duplicated-pub.rs:1:1 + | +LL | pub const pub fn test() {} + | ^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/parser/issue-87694-misplaced-pub.rs b/src/test/ui/parser/issue-87694-misplaced-pub.rs new file mode 100644 index 00000000000..3f824617cad --- /dev/null +++ b/src/test/ui/parser/issue-87694-misplaced-pub.rs @@ -0,0 +1,5 @@ +const pub fn test() {} +//~^ ERROR expected one of `async`, `extern`, `fn`, or `unsafe`, found keyword `pub` +//~| NOTE expected one of `async`, `extern`, `fn`, or `unsafe` +//~| HELP visibility `pub` must come before `const` +//~| SUGGESTION pub const diff --git a/src/test/ui/parser/issue-87694-misplaced-pub.stderr b/src/test/ui/parser/issue-87694-misplaced-pub.stderr new file mode 100644 index 00000000000..94c6a29efcb --- /dev/null +++ b/src/test/ui/parser/issue-87694-misplaced-pub.stderr @@ -0,0 +1,11 @@ +error: expected one of `async`, `extern`, `fn`, or `unsafe`, found keyword `pub` + --> $DIR/issue-87694-misplaced-pub.rs:1:7 + | +LL | const pub fn test() {} + | ------^^^ + | | | + | | expected one of `async`, `extern`, `fn`, or `unsafe` + | help: visibility `pub` must come before `const`: `pub const` + +error: aborting due to previous error + diff --git a/src/test/ui/parser/issues/issue-87217-keyword-order/const-async-const.rs b/src/test/ui/parser/issues/issue-87217-keyword-order/const-async-const.rs index 7c3d915a4c0..df0cd54399a 100644 --- a/src/test/ui/parser/issues/issue-87217-keyword-order/const-async-const.rs +++ b/src/test/ui/parser/issues/issue-87217-keyword-order/const-async-const.rs @@ -1,11 +1,9 @@ // edition:2018 -// Test that even when `const` is already present, the proposed fix is `const const async`, -// like for `pub pub`. +// Test that even when `const` is already present, the proposed fix is to remove the second `const` const async const fn test() {} //~^ ERROR expected one of `extern`, `fn`, or `unsafe`, found keyword `const` //~| NOTE expected one of `extern`, `fn`, or `unsafe` -//~| HELP `const` must come before `async` -//~| SUGGESTION const async -//~| NOTE keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern` +//~| HELP `const` already used earlier, remove this one +//~| NOTE `const` first seen here diff --git a/src/test/ui/parser/issues/issue-87217-keyword-order/const-async-const.stderr b/src/test/ui/parser/issues/issue-87217-keyword-order/const-async-const.stderr index 56280912540..977c6ebfef3 100644 --- a/src/test/ui/parser/issues/issue-87217-keyword-order/const-async-const.stderr +++ b/src/test/ui/parser/issues/issue-87217-keyword-order/const-async-const.stderr @@ -1,13 +1,17 @@ error: expected one of `extern`, `fn`, or `unsafe`, found keyword `const` - --> $DIR/const-async-const.rs:6:13 + --> $DIR/const-async-const.rs:5:13 | LL | const async const fn test() {} - | ------^^^^^ - | | | - | | expected one of `extern`, `fn`, or `unsafe` - | help: `const` must come before `async`: `const async` + | ^^^^^ + | | + | expected one of `extern`, `fn`, or `unsafe` + | help: `const` already used earlier, remove this one | - = note: keyword order for functions declaration is `default`, `pub`, `const`, `async`, `unsafe`, `extern` +note: `const` first seen here + --> $DIR/const-async-const.rs:5:1 + | +LL | const async const fn test() {} + | ^^^^^ error: aborting due to previous error |
