Produce targeted diagnostic when using doc comments on fn args
Before parsing argument names and types, try to consume an incorrectly included doc comment or attribute in order to recover and continue parsing the rest of the fn definition.
This commit is contained in:
parent
3e6f30ec3e
commit
ea57134607
7 changed files with 152 additions and 5 deletions
37
src/test/ui/parser/fn-arg-doc-comment.rs
Normal file
37
src/test/ui/parser/fn-arg-doc-comment.rs
Normal file
|
|
@ -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
|
||||
}
|
||||
63
src/test/ui/parser/fn-arg-doc-comment.stderr
Normal file
63
src/test/ui/parser/fn-arg-doc-comment.stderr
Normal file
|
|
@ -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`.
|
||||
|
|
@ -2,7 +2,10 @@ error: expected pattern, found `*`
|
|||
--> $DIR/issue-33413.rs:14:10
|
||||
|
|
||||
LL | fn f(*, a: u8) -> u8 {} //~ ERROR expected pattern, found `*`
|
||||
| ^ expected pattern
|
||||
| ^
|
||||
| |
|
||||
| expected pattern
|
||||
| expected argument name
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ error: unexpected lifetime `'a` in pattern
|
|||
--> $DIR/lifetime-in-pattern.rs:13:10
|
||||
|
|
||||
LL | fn test(&'a str) {
|
||||
| ^^ unexpected lifetime
|
||||
| ^^
|
||||
| |
|
||||
| unexpected lifetime
|
||||
| expected argument name
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ error: expected pattern, found `+`
|
|||
--> $DIR/removed-syntax-mode.rs:13:6
|
||||
|
|
||||
LL | fn f(+x: isize) {} //~ ERROR expected pattern, found `+`
|
||||
| ^ expected pattern
|
||||
| ^
|
||||
| |
|
||||
| expected pattern
|
||||
| expected argument name
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ error: unexpected lifetime `'a` in pattern
|
|||
--> $DIR/self-vs-path-ambiguity.rs:19:11
|
||||
|
|
||||
LL | fn i(&'a self::S: &S) {} //~ ERROR unexpected lifetime `'a` in pattern
|
||||
| ^^ unexpected lifetime
|
||||
| ^^
|
||||
| |
|
||||
| unexpected lifetime
|
||||
| expected argument name
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue