Closed
Description
Hi! 👋
Given the following code:
struct Foo {
bar: String,
}
impl Foo {
pub fn new(bar: impl ToString) -> Self {
Self {
bar: bar.into(),
}
}
}
The current output (stable / beta / nightly) is:
error[E0277]: the trait bound `String: From<impl ToString>` is not satisfied
--> src/lib.rs:8:22
|
8 | bar: bar.into(),
| ^^^^ the trait `From<impl ToString>` is not implemented for `String`
|
= note: required because of the requirements on the impl of `Into<String>` for `impl ToString`
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
|
5 | impl Foo where String: From<impl ToString> {
| +++++++++++++++++++++++++++++++++
For more information about this error, try `rustc --explain E0277`.
The issue is that I've used bar.into()
instead of bar.to_string()
-- and while the compiler suggesting to replace .into()
with .to_string()
would be pretty cool, at the very least I think it shouldn't propose adding where String: From<impl ToString>
(which is both illegal & pretty pointless).