Open andreytkachenko opened 6 years ago
There is a difference -- you need a coercion to convert from the concrete type of some boxed split iterator Box<Split<..>
into Box<Iterator<..>>
(unsizing coercion). The .map()
version does not support this, or rather, a value inside the map
's closure will not coerce due to the expected type outside the map. I haven't found an open or closed issue on this topic, but there might be one already.
For completeness: the simplest explicit way to get this to compile is
fn to_words<'a>() -> Option<Box<Iterator<Item = &'a str> + 'a>> {
xxx().map(|x| Box::new(x.split(' ')) as Box<Iterator<Item = _>>)
}
It would be awesome if the compiler could infer casts like this through closure boundaries though!
Triage: no change
Consider this snippet:
it won't compiles with the error:
but match in exactly same case compiles well:
And if I explicitly define closure's argument type and returning value type it also compiles well:
I am sure there should not be differences between match and map at all.
This issue is reproduceble on rust stable and nightly.