diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-10-03 04:08:14 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-03 04:08:14 +0200 |
| commit | faf2e8087c54d2a778e293f093a34fa18f48f0f2 (patch) | |
| tree | d9e1ff20f5438bb7af5e302dfb19911b9742c1f2 /src/test | |
| parent | 17b1fd1a8f1cdb9fbe1220aa5f7d8d568be6b4aa (diff) | |
| parent | 2537a8aa7a44d76b3345b98f394f6d2744f3a9cc (diff) | |
| download | rust-faf2e8087c54d2a778e293f093a34fa18f48f0f2.tar.gz rust-faf2e8087c54d2a778e293f093a34fa18f48f0f2.zip | |
Rollup merge of #64959 - davidtwco:issue-64252-self-type-help, r=Centril,estebank
syntax: improve parameter without type suggestions Fixes #64252. This PR improves the suggestions provided when function parameters do not have types: - A new suggestion is added for arbitrary self types, which suggests adding `self: ` before the type. - Existing suggestions are now provided when a `<` is found where a `:` was expected (previously only `,` and `)` or trait items), this gives suggestions in the case where the unnamed parameter type is generic in a free function. - The suggestion that a type name be provided (e.g. `fn foo(HashMap<u32>)` -> `fn foo(HashMap: TypeName<u32>)`) will no longer occur when a `<` was found instead of `:`. - The ident will not be used for recovery when a `<` was found instead of `:`. r? @Centril cc @estebank @yoshuawuyts
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/anon-params-denied-2018.stderr | 8 | ||||
| -rw-r--r-- | src/test/ui/parser/pat-lt-bracket-2.stderr | 6 | ||||
| -rw-r--r-- | src/test/ui/rfc-2565-param-attrs/param-attrs-2018.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/span/issue-34264.stderr | 6 | ||||
| -rw-r--r-- | src/test/ui/suggestions/issue-64252-self-type.rs | 14 | ||||
| -rw-r--r-- | src/test/ui/suggestions/issue-64252-self-type.stderr | 30 |
6 files changed, 68 insertions, 0 deletions
diff --git a/src/test/ui/anon-params-denied-2018.stderr b/src/test/ui/anon-params-denied-2018.stderr index a58998e4891..3fcf41a9a60 100644 --- a/src/test/ui/anon-params-denied-2018.stderr +++ b/src/test/ui/anon-params-denied-2018.stderr @@ -5,6 +5,10 @@ LL | fn foo(i32); | ^ expected one of `:`, `@`, or `|` here | = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) +help: if this is a `self` type, give it a parameter name + | +LL | fn foo(self: i32); + | ^^^^^^^^^ help: if this was a parameter name, give it a type | LL | fn foo(i32: TypeName); @@ -21,6 +25,10 @@ LL | fn bar_with_default_impl(String, String) {} | ^ expected one of `:`, `@`, or `|` here | = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) +help: if this is a `self` type, give it a parameter name + | +LL | fn bar_with_default_impl(self: String, String) {} + | ^^^^^^^^^^^^ help: if this was a parameter name, give it a type | LL | fn bar_with_default_impl(String: TypeName, String) {} diff --git a/src/test/ui/parser/pat-lt-bracket-2.stderr b/src/test/ui/parser/pat-lt-bracket-2.stderr index dbc8d0f5865..2191e31ad1f 100644 --- a/src/test/ui/parser/pat-lt-bracket-2.stderr +++ b/src/test/ui/parser/pat-lt-bracket-2.stderr @@ -3,6 +3,12 @@ error: expected one of `:`, `@`, or `|`, found `<` | LL | fn a(B<) {} | ^ expected one of `:`, `@`, or `|` here + | + = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) +help: if this is a type, explicitly ignore the parameter name + | +LL | fn a(_: B<) {} + | ^^^^ error: aborting due to previous error diff --git a/src/test/ui/rfc-2565-param-attrs/param-attrs-2018.stderr b/src/test/ui/rfc-2565-param-attrs/param-attrs-2018.stderr index 9860e9805b2..e4248f3b974 100644 --- a/src/test/ui/rfc-2565-param-attrs/param-attrs-2018.stderr +++ b/src/test/ui/rfc-2565-param-attrs/param-attrs-2018.stderr @@ -5,6 +5,10 @@ LL | trait Trait2015 { fn foo(#[allow(C)] i32); } | ^ expected one of `:`, `@`, or `|` here | = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) +help: if this is a `self` type, give it a parameter name + | +LL | trait Trait2015 { fn foo(#[allow(C)] self: i32); } + | ^^^^^^^^^ help: if this was a parameter name, give it a type | LL | trait Trait2015 { fn foo(#[allow(C)] i32: TypeName); } diff --git a/src/test/ui/span/issue-34264.stderr b/src/test/ui/span/issue-34264.stderr index cc0eccd37a2..8d4a66f142d 100644 --- a/src/test/ui/span/issue-34264.stderr +++ b/src/test/ui/span/issue-34264.stderr @@ -3,6 +3,12 @@ error: expected one of `:`, `@`, or `|`, found `<` | LL | fn foo(Option<i32>, String) {} | ^ expected one of `:`, `@`, or `|` here + | + = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) +help: if this is a type, explicitly ignore the parameter name + | +LL | fn foo(_: Option<i32>, String) {} + | ^^^^^^^^^ error: expected one of `:`, `@`, or `|`, found `)` --> $DIR/issue-34264.rs:1:27 diff --git a/src/test/ui/suggestions/issue-64252-self-type.rs b/src/test/ui/suggestions/issue-64252-self-type.rs new file mode 100644 index 00000000000..128d5e85c22 --- /dev/null +++ b/src/test/ui/suggestions/issue-64252-self-type.rs @@ -0,0 +1,14 @@ +// This test checks that a suggestion to add a `self: ` parameter name is provided +// to functions where this is applicable. + +pub fn foo(Box<Self>) { } +//~^ ERROR expected one of `:`, `@`, or `|`, found `<` + +struct Bar; + +impl Bar { + fn bar(Box<Self>) { } + //~^ ERROR expected one of `:`, `@`, or `|`, found `<` +} + +fn main() { } diff --git a/src/test/ui/suggestions/issue-64252-self-type.stderr b/src/test/ui/suggestions/issue-64252-self-type.stderr new file mode 100644 index 00000000000..fa28a0d684e --- /dev/null +++ b/src/test/ui/suggestions/issue-64252-self-type.stderr @@ -0,0 +1,30 @@ +error: expected one of `:`, `@`, or `|`, found `<` + --> $DIR/issue-64252-self-type.rs:4:15 + | +LL | pub fn foo(Box<Self>) { } + | ^ expected one of `:`, `@`, or `|` here + | + = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) +help: if this is a type, explicitly ignore the parameter name + | +LL | pub fn foo(_: Box<Self>) { } + | ^^^^^^ + +error: expected one of `:`, `@`, or `|`, found `<` + --> $DIR/issue-64252-self-type.rs:10:15 + | +LL | fn bar(Box<Self>) { } + | ^ expected one of `:`, `@`, or `|` here + | + = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) +help: if this is a `self` type, give it a parameter name + | +LL | fn bar(self: Box<Self>) { } + | ^^^^^^^^^ +help: if this is a type, explicitly ignore the parameter name + | +LL | fn bar(_: Box<Self>) { } + | ^^^^^^ + +error: aborting due to 2 previous errors + |
