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
This commit is contained in:
Matthias Krüger 2021-12-18 08:16:25 +01:00 committed by GitHub
commit 54e7946d0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 154 additions and 45 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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