Closed
Description
I saw this broken code on IRC:
pub trait JoinWithString {
fn join(self, separator: &'static str) -> String;
}
impl<X> JoinWithString for X
where X: Iterator<Item = String>
{
fn join(self, separator: &'static str) -> String {
unimplemented!()
}
}
fn main() {
let a: Vec<std::path::PathBuf> = Vec::new();
a.iter().map(|x| x.to_str().unwrap()).join(":");
}
I know why it's broken, but I don't like the error message:
error: no method named `join` found for type `std::iter::Map<std::slice::Iter<'_, std::path::PathBuf>, [closure@<anon>:16:18: 16:41]>` in the current scope
--> <anon>:16:43
|>
16 |> a.iter().map(|x| x.to_str().unwrap()).join(":");
|> ^^^^
note: the method `join` exists but the following trait bounds were not satisfied: `&std::iter::Map<std::slice::Iter<'_, std::path::PathBuf>, [closure@<anon>:16:18: 16:41]> : std::iter::Iterator`
help: items from traits can only be used if the trait is implemented and in scope; the following trait defines an item `join`, perhaps you need to implement it:
help: candidate #1: `JoinWithString`
- The
note
just told me that the problem is the trait bounds, so it is superfluous to suggest importing a trait (even without thenote
, it doesn't need to be imported so thehelp
is useless). - The
note
saysIterator
is not satisfied, which is not helpful. The problem is thatIterator<Item=String>
is not satisfied.