Open camsteffen opened 2 years ago
T::fun
is a projection through T
and thus is lifetime-limited by the lifetime of T
as per RFC 1214. This is what E0310 is talking about in your example, and why it recommends adding a T: 'static
bound.
This works as, per RFC 401, function types coerce to function pointers with the same argument signatures:
takes_static_fn(T::fun as fn());
And this is fine because it always calls the lifetime-limited function item, but doesn't capture environment and thus also coerces as per RFC 401:
takes_static_fn(|| T::fun());
Edit: Ehh, not coerces, but implements Fn()
statically.
Triage: Since the behavior is following RFC 1214, changing this would presumably require a new RFC that complements RFC 1214. I added a needs-rfc label.
Triage: https://github.com/rust-lang/rust/issues/85456 is older, but this issue is more succinct, so I closed that issue as duplicate to this one.