Closed
Description
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