diff options
| author | bors <bors@rust-lang.org> | 2018-11-05 16:36:18 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-11-05 16:36:18 +0000 |
| commit | af791bb8f4a9b93c701aa11fd05759d96898cee2 (patch) | |
| tree | bb9b4f0ef0637ecb7396dc037cd5ae54d25be5dd /src/test/ui/parser | |
| parent | 6cfc6033955dd2685dfa7baeec6f6bc3bfdfe2f1 (diff) | |
| parent | adb96ec64b8d5e8cff191315668a5bfe0480909c (diff) | |
| download | rust-af791bb8f4a9b93c701aa11fd05759d96898cee2.tar.gz rust-af791bb8f4a9b93c701aa11fd05759d96898cee2.zip | |
Auto merge of #55451 - estebank:arg-doc, r=pnkfelix
Custom diagnostic when trying to doc comment argument
When writing
```
pub fn f(
/// Comment
id: u8,
) {}
```
Produce a targeted diagnostic
```
error: documentation comments cannot be applied to method arguments
--> $DIR/fn-arg-doc-comment.rs:2:5
|
LL | /// Comment
| ^^^^^^^^^^^ doc comments are not allowed here
```
Fix #54801.
Diffstat (limited to 'src/test/ui/parser')
| -rw-r--r-- | src/test/ui/parser/fn-arg-doc-comment.rs | 37 | ||||
| -rw-r--r-- | src/test/ui/parser/fn-arg-doc-comment.stderr | 63 | ||||
| -rw-r--r-- | src/test/ui/parser/issue-33413.rs | 3 | ||||
| -rw-r--r-- | src/test/ui/parser/issue-33413.stderr | 6 | ||||
| -rw-r--r-- | src/test/ui/parser/match-refactor-to-expr.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/parser/match-refactor-to-expr.stderr | 7 | ||||
| -rw-r--r-- | src/test/ui/parser/removed-syntax-mode.rs | 3 | ||||
| -rw-r--r-- | src/test/ui/parser/removed-syntax-mode.stderr | 6 |
8 files changed, 116 insertions, 11 deletions
diff --git a/src/test/ui/parser/fn-arg-doc-comment.rs b/src/test/ui/parser/fn-arg-doc-comment.rs new file mode 100644 index 00000000000..22af94b6284 --- /dev/null +++ b/src/test/ui/parser/fn-arg-doc-comment.rs @@ -0,0 +1,37 @@ +pub fn f( + /// Comment + //~^ ERROR documentation comments cannot be applied to method arguments + //~| NOTE doc comments are not allowed here + id: u8, + /// Other + //~^ ERROR documentation comments cannot be applied to method arguments + //~| NOTE doc comments are not allowed here + a: u8, +) {} + +fn foo(#[allow(dead_code)] id: i32) {} +//~^ ERROR attributes cannot be applied to method arguments +//~| NOTE attributes are not allowed here + +fn bar(id: #[allow(dead_code)] i32) {} +//~^ ERROR attributes cannot be applied to a method argument's type +//~| NOTE attributes are not allowed here + +fn main() { + // verify that the parser recovered and properly typechecked the args + f("", ""); + //~^ ERROR mismatched types + //~| NOTE expected u8, found reference + //~| NOTE expected + //~| ERROR mismatched types + //~| NOTE expected u8, found reference + //~| NOTE expected + foo(""); + //~^ ERROR mismatched types + //~| NOTE expected i32, found reference + //~| NOTE expected + bar(""); + //~^ ERROR mismatched types + //~| NOTE expected i32, found reference + //~| NOTE expected +} diff --git a/src/test/ui/parser/fn-arg-doc-comment.stderr b/src/test/ui/parser/fn-arg-doc-comment.stderr new file mode 100644 index 00000000000..73a24eebb3f --- /dev/null +++ b/src/test/ui/parser/fn-arg-doc-comment.stderr @@ -0,0 +1,63 @@ +error: documentation comments cannot be applied to method arguments + --> $DIR/fn-arg-doc-comment.rs:2:5 + | +LL | /// Comment + | ^^^^^^^^^^^ doc comments are not allowed here + +error: documentation comments cannot be applied to method arguments + --> $DIR/fn-arg-doc-comment.rs:6:5 + | +LL | /// Other + | ^^^^^^^^^ doc comments are not allowed here + +error: attributes cannot be applied to method arguments + --> $DIR/fn-arg-doc-comment.rs:12:8 + | +LL | fn foo(#[allow(dead_code)] id: i32) {} + | ^^^^^^^^^^^^^^^^^^^ attributes are not allowed here + +error: attributes cannot be applied to a method argument's type + --> $DIR/fn-arg-doc-comment.rs:16:12 + | +LL | fn bar(id: #[allow(dead_code)] i32) {} + | ^^^^^^^^^^^^^^^^^^^ attributes are not allowed here + +error[E0308]: mismatched types + --> $DIR/fn-arg-doc-comment.rs:22:7 + | +LL | f("", ""); + | ^^ expected u8, found reference + | + = note: expected type `u8` + found type `&'static str` + +error[E0308]: mismatched types + --> $DIR/fn-arg-doc-comment.rs:22:11 + | +LL | f("", ""); + | ^^ expected u8, found reference + | + = note: expected type `u8` + found type `&'static str` + +error[E0308]: mismatched types + --> $DIR/fn-arg-doc-comment.rs:29:9 + | +LL | foo(""); + | ^^ expected i32, found reference + | + = note: expected type `i32` + found type `&'static str` + +error[E0308]: mismatched types + --> $DIR/fn-arg-doc-comment.rs:33:9 + | +LL | bar(""); + | ^^ expected i32, found reference + | + = note: expected type `i32` + found type `&'static str` + +error: aborting due to 8 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/parser/issue-33413.rs b/src/test/ui/parser/issue-33413.rs index 25ae7b4c55a..7c3b84a5185 100644 --- a/src/test/ui/parser/issue-33413.rs +++ b/src/test/ui/parser/issue-33413.rs @@ -11,5 +11,6 @@ // compile-flags: -Z parse-only impl S { - fn f(*, a: u8) -> u8 {} //~ ERROR expected pattern, found `*` + fn f(*, a: u8) -> u8 {} + //~^ ERROR expected argument name, found `*` } diff --git a/src/test/ui/parser/issue-33413.stderr b/src/test/ui/parser/issue-33413.stderr index 189ace74b9c..e0d69e596f2 100644 --- a/src/test/ui/parser/issue-33413.stderr +++ b/src/test/ui/parser/issue-33413.stderr @@ -1,8 +1,8 @@ -error: expected pattern, found `*` +error: expected argument name, found `*` --> $DIR/issue-33413.rs:14:10 | -LL | fn f(*, a: u8) -> u8 {} //~ ERROR expected pattern, found `*` - | ^ expected pattern +LL | fn f(*, a: u8) -> u8 {} + | ^ expected argument name error: aborting due to previous error diff --git a/src/test/ui/parser/match-refactor-to-expr.rs b/src/test/ui/parser/match-refactor-to-expr.rs index 3c88608697a..014dba3d4d0 100644 --- a/src/test/ui/parser/match-refactor-to-expr.rs +++ b/src/test/ui/parser/match-refactor-to-expr.rs @@ -12,7 +12,7 @@ fn main() { let foo = - match + match //~ NOTE while parsing this match expression Some(4).unwrap_or_else(5) //~^ NOTE expected one of `.`, `?`, `{`, or an operator here ; //~ NOTE unexpected token diff --git a/src/test/ui/parser/match-refactor-to-expr.stderr b/src/test/ui/parser/match-refactor-to-expr.stderr index ecca781684c..2ffbddd570f 100644 --- a/src/test/ui/parser/match-refactor-to-expr.stderr +++ b/src/test/ui/parser/match-refactor-to-expr.stderr @@ -1,8 +1,11 @@ error: expected one of `.`, `?`, `{`, or an operator, found `;` --> $DIR/match-refactor-to-expr.rs:18:9 | -LL | match - | ----- help: try removing this `match` +LL | match //~ NOTE while parsing this match expression + | ----- + | | + | while parsing this match expression + | help: try removing this `match` LL | Some(4).unwrap_or_else(5) | - expected one of `.`, `?`, `{`, or an operator here LL | //~^ NOTE expected one of `.`, `?`, `{`, or an operator here diff --git a/src/test/ui/parser/removed-syntax-mode.rs b/src/test/ui/parser/removed-syntax-mode.rs index 6e99f8b3eea..c2f87d8afce 100644 --- a/src/test/ui/parser/removed-syntax-mode.rs +++ b/src/test/ui/parser/removed-syntax-mode.rs @@ -10,4 +10,5 @@ // compile-flags: -Z parse-only -fn f(+x: isize) {} //~ ERROR expected pattern, found `+` +fn f(+x: isize) {} +//~^ ERROR expected argument name, found `+` diff --git a/src/test/ui/parser/removed-syntax-mode.stderr b/src/test/ui/parser/removed-syntax-mode.stderr index 7a274553d57..7ad88471d5a 100644 --- a/src/test/ui/parser/removed-syntax-mode.stderr +++ b/src/test/ui/parser/removed-syntax-mode.stderr @@ -1,8 +1,8 @@ -error: expected pattern, found `+` +error: expected argument name, found `+` --> $DIR/removed-syntax-mode.rs:13:6 | -LL | fn f(+x: isize) {} //~ ERROR expected pattern, found `+` - | ^ expected pattern +LL | fn f(+x: isize) {} + | ^ expected argument name error: aborting due to previous error |
