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

Provide a structured suggestion for _-as-parameter-type in trait impls #95097

Closed
scottmcm opened this issue Mar 19, 2022 · 0 comments · Fixed by #95395
Closed

Provide a structured suggestion for _-as-parameter-type in trait impls #95097

scottmcm opened this issue Mar 19, 2022 · 0 comments · Fixed by #95395
Assignees
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

@scottmcm
Copy link
Member

Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=91ba3d382d71310c4e6239fc5d4da92f

struct Foo;

impl From<Vec<Vec<Vec<i32>>>> for Foo {
    fn from(x: _) -> Self { Self }
}

The current output is:

error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
 --> src/lib.rs:4:16
  |
4 |     fn from(x: _) -> Self { Self }
  |                ^ not allowed in type signatures
  |
help: use type parameters instead
  |
4 |     fn from<T>(x: T) -> Self { Self }
  |            +++    ~

That's a particularly-bad help in a trait impl, since the associated function is not generic, and thus adding a generic parameter definitely won't work.

Ideally the output should look like:

error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
 --> src/lib.rs:4:16
  |
4 |     fn from(x: _) -> Self { Self }
  |                ^ not allowed in type signatures
  |
help: use the type required by the trait instead
  |
4 |     fn from(x: Vec<Vec<Vec<i32>>>) -> Self { Self }
  |                ~~~~~~~~~~~~~~~~~~

So that, like happens with -> _, I can just accept the structured suggestion instead of needing to type out the long type again.

@scottmcm scottmcm 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 Mar 19, 2022
@scottmcm scottmcm changed the title Provide a structured suggestion for _ in trait impls Provide a structured suggestion for _-as-parameter-type in trait impls Mar 19, 2022
@compiler-errors compiler-errors self-assigned this Mar 28, 2022
@bors bors closed this as completed in 76aa9e5 Apr 25, 2022
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.

2 participants