Why does this borrow outlive its own scope – only when declared as a trait object?

Instead of having the lifetime on the trait, have it on the function:

trait ReturnIter {
    fn return_iter<'a>(&'a self) -> Box<dyn Iterator<Item = usize> + 'a>;
}
2 Likes