Closed
Description
Consider this code (playground):
fn main() {
let line = String::from("abc");
let pattern = String::from("bc");
println!("{:?}", line.find(pattern));
}
On both current stable and nightly, this results in this error message:
error[E0277]: expected a `std::ops::FnMut<(char,)>` closure, found `std::string::String`
--> src/main.rs:4:27
|
4 | println!("{:?}", line.find(pattern));
| ^^^^ expected an `FnMut<(char,)>` closure, found `std::string::String`
|
= help: the trait `std::ops::FnMut<(char,)>` is not implemented for `std::string::String`
= note: required because of the requirements on the impl of `std::str::pattern::Pattern<'_>` for `std::string::String`
error: aborting due to previous error
This is really confusing, since the proper way to get this to compile is to use a reference instead of an owned string:
- println!("{:?}", line.find(pattern));
+ println!("{:?}", line.find(&pattern));