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

Invalid type annotations needed suggestion that leads to E0632 #86162

Closed
nbdd0121 opened this issue Jun 9, 2021 · 0 comments · Fixed by #86338
Closed

Invalid type annotations needed suggestion that leads to E0632 #86162

nbdd0121 opened this issue Jun 9, 2021 · 0 comments · Fixed by #86338
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nbdd0121
Copy link
Contributor

nbdd0121 commented Jun 9, 2021

This code produces invalid suggestion:

fn foo(x: impl Clone) {}
fn gen<T>() -> T { todo!() }

fn main() {
    foo(gen());
}
error[E0283]: type annotations needed
 --> src/main.rs:5:5
  |
1 | fn foo(x: impl Clone) {}
  |                ----- required by this bound in `foo`
...
5 |     foo(gen());
  |     ^^^ cannot infer type for type parameter `impl Clone` declared on the function `foo`
  |
  = note: cannot satisfy `_: Clone`
help: consider specifying the type argument in the function call
  |
5 |     foo::<impl Clone>(gen());
  |        ^^^^^^^^^^^^^^

Also this code:

fn foo<const N: usize>(x: impl Clone) {}
fn gen<T>() -> T { todo!() }

fn main() {
    foo(gen());
}
error[E0283]: type annotations needed
 --> src/main.rs:5:5
  |
1 | fn foo<const N: usize>(x: impl Clone) {}
  |                                ----- required by this bound in `foo`
...
5 |     foo(gen());
  |     ^^^ cannot infer type for type parameter `impl Clone` declared on the function `foo`
  |
  = note: cannot satisfy `_: Clone`
help: consider specifying the type arguments in the function call
  |
5 |     foo::<N, impl Clone>(gen());
  |        ^^^^^^^^^^^^^^^^^

None of them produce valid suggestion, as what it suggests will produce error[E0632]: cannot provide explicit generic arguments when impl Trait is used in argument position.

Related to #83606.

@rustbot label: +A-diagnostics +D-invalid-suggestion +T-compiler

@nbdd0121 nbdd0121 added the C-bug Category: This is a bug. label Jun 9, 2021
@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 9, 2021
@JohnTitor JohnTitor self-assigned this Jun 15, 2021
@bors bors closed this as completed in d5fd37f Aug 3, 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 C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. 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.

3 participants