Closed
Description
This snippet:
fn foo(s: String) {}
fn main() {
let s = "this is a &str";
foo(s);
}
results in the following compiler error:
error[E0308]: mismatched types
--> src/main.rs:6:9
|
6 | foo(s);
| ^ expected struct `std::string::String`, found &str
|
= note: expected type `std::string::String`
found type `&str`
= help: here are some functions which might fulfill your needs:
- .escape_debug()
- .escape_default()
- .escape_unicode()
- .to_lowercase()
- .to_uppercase()
error: aborting due to previous error
error: Could not compile `playground`.
To learn more, run the command again with --verbose.
It would be nice if this error message suggested the function which is actually most likely to be helpful here, which is to_string()
.