Deref target may not live as long as a reference to its "wrapper"

Here's an example of something I found rather unexpected

pub trait HasItem {
    type Item;
    
    fn get_item(&self) -> &Self::Item;
}

impl<T, R> HasItem for R 
where
    T: HasItem,
    R: std::ops::Deref<Target = T> 
{
    type Item = T::Item;
    
    fn get_item(&self) -> &Self::Item {
        self.deref().get_item()
    }
}

This fails to compile, claiming that T doesn't live long enough.

My understanding is that these traits/impls get desugared to:

pub trait HasItem {
    type Item;
    
    fn get_item<'a>(&'a self) -> &'a Self::Item;
}

impl<T, R> HasItem for R 
where
    T: HasItem,
    R: std::ops::Deref<Target = T> 
{
    type Item = T::Item;
    
    fn get_item<'a>(&'a self) -> &'a Self::Item {
        self.deref().get_item()
    }
}

My question is, in what cases may a R be able to return a reference to a T where T wouldn't live as long as a reference to R?

Just specify a different lifetime for the returned value so that it's not the same as of Self. This works:

pub trait HasItem<'a> {
    type Item;
    
    fn get_item(&self) -> &'a Self::Item;
}

impl<'a, T, R> HasItem<'a> for R 
where
    T: HasItem<'a>,
    R: std::ops::Deref<Target = T> 
{
    type Item = T::Item;
    
    fn get_item(&self) -> &'a Self::Item {
        self.deref().get_item()
    }
}

This feels like this issue but for implied lifetime bounds to me. Getting rid of the type equality allows it to compile.

If R: 'a, then <R as Deref>::Target: 'a.

If T 'a, then <T as HasItem>::Item: 'a.

So it can't happen, and this is a weakness in the type or trait system or such.

Oh thats a very interesting workaround!

Thanks @quinedot !