Closed
Description
Given the following code: playground
#![feature(generic_associated_types)]
trait StreamingIter {
type Item<'a> where Self: 'a;
fn next<'a>(&'a mut self) -> Option<Self::Item::<'a>>;
}
struct StreamingSliceIter<'a, T> {
idx: usize,
data: &'a mut [T],
}
impl<'b, T: 'b> StreamingIter for StreamingSliceIter<'b, T> {
type Item<'a> = &'a mut T;
fn next(&mut self) -> Option<&mut T> {
self.idx += 1;
Some(&mut self.data[self.idx - 1])
}
}
The current output is:
error[E0309]: the parameter type `T` may not live long enough
--> src/lib.rs:14:5
|
13 | impl<'b, T: 'b> StreamingIter for StreamingSliceIter<'b, T> {
| -- help: consider adding an explicit lifetime bound...: `T: 'a +`
14 | type Item<'a> = &'a mut T;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the reference type `&'a mut T` does not outlive the data it points at
error: aborting due to previous error;
I'm not really sure what the correct output should be but it should mention that I forgot the where Self: 'a
bound on the trait impl like I have it written in this compiling code. It should also not suggest adding adding a T: 'a
bound because that bound is not writeable 😅