Impl trait return types are currently bounded by all type parameters and will eventually be bounded by all lifetime parameters too. But sometimes the trait bounds imply they cannot capture generic parameters, e.g., fn foo<T>() -> impl 'static cannot capture T, since T is not known to be 'static. We mostly recognize this but do not always take advantage of it correctly.
Impl trait return types are currently bounded by all type parameters and will eventually be bounded by all lifetime parameters too. But sometimes the trait bounds imply they cannot capture generic parameters, e.g.,
fn foo<T>() -> impl 'static
cannot captureT
, sinceT
is not known to be'static
. We mostly recognize this but do not always take advantage of it correctly.cc https://github.com/rust-lang/rust/issues/42940