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

Diagnostic for impl for S should also suggest syntax for inherit impl #88818

Closed
jruderman opened this issue Sep 10, 2021 · 0 comments · Fixed by #88894
Closed

Diagnostic for impl for S should also suggest syntax for inherit impl #88818

jruderman opened this issue Sep 10, 2021 · 0 comments · Fixed by #88894
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jruderman
Copy link
Contributor

jruderman commented Sep 10, 2021

Given the following code:

struct S { }
impl for S { }

The current output is:

error: missing trait in a trait impl
 --> src/lib.rs:2:5
  |
2 | impl for S { }
  |     ^

Ideally the output should look like:

help: to implement trait items for struct S, write `impl TraitName for S { ... }`
help: to implement inherit items for struct S, write `impl S { ... }`

Followup to #56031

@jruderman jruderman added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 10, 2021
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Sep 14, 2021
Improve error message for missing trait in trait impl

Fixes rust-lang#88818. For the following example:
```rust
struct S { }
impl for S { }
```
the current output is:
```
error: missing trait in a trait impl
 --> t1.rs:2:5
  |
2 | impl for S { }
  |     ^
```
With my changes, I get:
```
error: missing trait in a trait impl
 --> t1.rs:2:5
  |
2 | impl for S { }
  |     ^
  |
help: add a trait here
  |
2 | impl Trait for S { }
  |      +++++
help: for an inherent impl, drop this `for`
  |
2 - impl for S { }
2 + impl S { }
  |
```
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Sep 14, 2021
Improve error message for missing trait in trait impl

Fixes rust-lang#88818. For the following example:
```rust
struct S { }
impl for S { }
```
the current output is:
```
error: missing trait in a trait impl
 --> t1.rs:2:5
  |
2 | impl for S { }
  |     ^
```
With my changes, I get:
```
error: missing trait in a trait impl
 --> t1.rs:2:5
  |
2 | impl for S { }
  |     ^
  |
help: add a trait here
  |
2 | impl Trait for S { }
  |      +++++
help: for an inherent impl, drop this `for`
  |
2 - impl for S { }
2 + impl S { }
  |
```
@bors bors closed this as completed in 84d65fe Sep 14, 2021
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 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.

1 participant