forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#64959 - davidtwco:issue-64252-self-type-hel…
…p, r=Centril,estebank syntax: improve parameter without type suggestions Fixes rust-lang#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
- Loading branch information
Showing
8 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|