Difference between these two trait defs?

Came across them in this topic

trait Env<'arena> {
    type Arena: 'static;
    fn init() -> Self::Arena;
}
trait HasArena {
    type Arena;
}

trait Env<'arena>: HasArena {
    fn init() -> Self::Arena;
}

Ignoring the different places the associated type is defined in, do they behave differently? (It's known that they behave differently from this definition; see the linked topic)

trait Env<'arena> {
    type Arena;
    fn init() -> Self::Arena;
}

Sure, of course they're different. In the second case, the Arena associated type need not be 'static. Non-'static lifetimes aren't only made available by generic lifetime parameters on the trait; they can also be introduced by the type itself. For instance,

struct Foo<'a>(&'a ());

impl<'a> HasArena for Foo<'a> {
    type Arena = &'a bumpalo::Bump;
}

impl<'arena, 'a> Env<'arena> for Foo<'a> {
    fn init() -> Self::Arena {
        todo!()
    }
}
2 Likes