Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diagnostics: help text for missing left-hand side in arbitrary self type #64252

Closed
yoshuawuyts opened this issue Sep 7, 2019 · 1 comment · Fixed by #64959
Closed

Diagnostics: help text for missing left-hand side in arbitrary self type #64252

yoshuawuyts opened this issue Sep 7, 2019 · 1 comment · Fixed by #64959
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@yoshuawuyts
Copy link
Member

Forgetting to include the left-hand side of an arbitrary self type can give some confusing errors. This was reported by someone trying to implement a future manually, and the diagnostics threw them off.

I realize diagnostics for arbitrary self types are an open issue, but figured I'd include this variant as to not overlook it. Thanks!

Link to playground

Code

pub fn hello(Box<Self>) {}

Expected

error: expected one of `:` or `@`, found `<`
 --> src/lib.rs:1:17
  |
1 | pub fn hello(Box<Self>) {}
  |              ^ expected one of `:` or `@` here
  |
help: if this is a `self` type, give it a parameter name
  |
1 | pub fn hello(self: Box<Self>) {}
  |              ^^^^^^^^^^^^^^^

error: aborting due to previous error

Current

error: expected one of `:` or `@`, found `<`
 --> src/lib.rs:1:17
  |
1 | pub fn hello(Box<Self>) {}
  |                 ^ expected one of `:` or `@` here

error: aborting due to previous error
@Centril
Copy link
Contributor

Centril commented Sep 7, 2019

The output with:

impl Foo for Baz {
    pub fn hello(Box<Self>) {}
}

is:

error: expected one of `:` or `@`, found `<`
 --> src/lib.rs:2:21
  |
2 |     pub fn hello(Box<Self>) {}
  |                     ^ expected one of `:` or `@` here
  |
  = note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
help: if this was a parameter name, give it a type
  |
2 |     pub fn hello(Box: TypeName<Self>) {}
  |                  ^^^^^^^^^^^^^
help: if this is a type, explicitly ignore the parameter name
  |
2 |     pub fn hello(_: Box<Self>) {}
  |                  ^^^^^^

error: aborting due to previous error

@Centril Centril self-assigned this Sep 7, 2019
@Centril Centril added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Sep 7, 2019
@Centril Centril removed their assignment Sep 30, 2019
Centril added a commit to Centril/rust that referenced this issue Oct 1, 2019
syntax: cleanup param, method, and misc parsing

Do some misc cleanup of the parser:
- Method and parameter parsing is refactored.
- A parser for `const | mut` is introduced that rust-lang#64588 can reuse.
- Some other misc parsing.

Next up in a different PR:
- ~Implementing rust-lang#64252 -- maybe some other time...
- Heavily restructuring up `item.rs` which is a mess (hopefully, no promises ^^).

r? @petrochenkov
Centril added a commit to Centril/rust that referenced this issue Oct 1, 2019
syntax: cleanup param, method, and misc parsing

Do some misc cleanup of the parser:
- Method and parameter parsing is refactored.
- A parser for `const | mut` is introduced that rust-lang#64588 can reuse.
- Some other misc parsing.

Next up in a different PR:
- ~Implementing rust-lang#64252 -- maybe some other time...
- Heavily restructuring up `item.rs` which is a mess (hopefully, no promises ^^).

r? @petrochenkov
Centril added a commit to Centril/rust that referenced this issue Oct 1, 2019
syntax: cleanup param, method, and misc parsing

Do some misc cleanup of the parser:
- Method and parameter parsing is refactored.
- A parser for `const | mut` is introduced that rust-lang#64588 can reuse.
- Some other misc parsing.

Next up in a different PR:
- ~Implementing rust-lang#64252 -- maybe some other time...
- Heavily restructuring up `item.rs` which is a mess (hopefully, no promises ^^).

r? @petrochenkov
Centril added a commit to Centril/rust that referenced this issue Oct 1, 2019
syntax: cleanup param, method, and misc parsing

Do some misc cleanup of the parser:
- Method and parameter parsing is refactored.
- A parser for `const | mut` is introduced that rust-lang#64588 can reuse.
- Some other misc parsing.

Next up in a different PR:
- ~Implementing rust-lang#64252 -- maybe some other time...
- Heavily restructuring up `item.rs` which is a mess (hopefully, no promises ^^).

r? @petrochenkov
tmandry added a commit to tmandry/rust that referenced this issue Oct 1, 2019
syntax: cleanup param, method, and misc parsing

Do some misc cleanup of the parser:
- Method and parameter parsing is refactored.
- A parser for `const | mut` is introduced that rust-lang#64588 can reuse.
- Some other misc parsing.

Next up in a different PR:
- ~Implementing rust-lang#64252 -- maybe some other time...
- Heavily restructuring up `item.rs` which is a mess (hopefully, no promises ^^).

r? @petrochenkov
tmandry added a commit to tmandry/rust that referenced this issue Oct 1, 2019
syntax: cleanup param, method, and misc parsing

Do some misc cleanup of the parser:
- Method and parameter parsing is refactored.
- A parser for `const | mut` is introduced that rust-lang#64588 can reuse.
- Some other misc parsing.

Next up in a different PR:
- ~Implementing rust-lang#64252 -- maybe some other time...
- Heavily restructuring up `item.rs` which is a mess (hopefully, no promises ^^).

r? @petrochenkov
Centril added a commit to Centril/rust that referenced this issue Oct 1, 2019
syntax: cleanup param, method, and misc parsing

Do some misc cleanup of the parser:
- Method and parameter parsing is refactored.
- A parser for `const | mut` is introduced that rust-lang#64588 can reuse.
- Some other misc parsing.

Next up in a different PR:
- ~Implementing rust-lang#64252 -- maybe some other time...
- Heavily restructuring up `item.rs` which is a mess (hopefully, no promises ^^).

r? @petrochenkov
Centril added a commit to Centril/rust that referenced this issue Oct 1, 2019
syntax: cleanup param, method, and misc parsing

Do some misc cleanup of the parser:
- Method and parameter parsing is refactored.
- A parser for `const | mut` is introduced that rust-lang#64588 can reuse.
- Some other misc parsing.

Next up in a different PR:
- ~Implementing rust-lang#64252 -- maybe some other time...
- Heavily restructuring up `item.rs` which is a mess (hopefully, no promises ^^).

r? @petrochenkov
Manishearth added a commit to Manishearth/rust that referenced this issue Oct 2, 2019
…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
Centril added a commit to Centril/rust that referenced this issue Oct 2, 2019
…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
@bors bors closed this as completed in faf2e80 Oct 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants