Why is an explicity lifetime trait bound needed in the example?

The rules are syntactical and presence of &'a T in arguments are part of the rules but the presence of &'a T: Trait are not.


This requires the bounds, like a reference does.

#[derive(Clone, Copy)]
struct NonRef<'a, T: 'a>(&'a T);

fn foo<'a, T>() where NonRef<'a, T>: Copy {}

This requires the T: Copy bound too.

struct Bar<T: Copy>(T);

fn foo<T>() where Bar<T>: {}

This RFC would make the latter bounds implied, and probably the former too (still haven't done the legwork). But there are negative consequences too, so I'm not convinced it's a net benefit. Maybe there are less or no negative consequences for lifetimes specifically, but I'm not confident about that (still haven't done the legwork).

There's a lot of details in the implied bounds I haven't deep-dived on; perhaps they lend insight on why this isn't a slam-dunk to implement either. (As far as I know it's still waiting on the next-generation trait solver.)

3 Likes