Hello there, Rust newbie here. I'm trying to get straight about this lifetime constraint that requires 'a outlives 'b it's clear that i is a temporary value and simply lives shorter than 'a. But this code simply cannot compile. It says i dropped while still borrowed. Why this fails?
No, this is not true; the trait that contains needs_ref is generic over 'b, so needs_ref can't be any more concrete than that; it must be (transitively) generic over 'b.
However, luckily, this has nothing to do with the issue at hand!
The generic lifetime parameters (and in general, all generic parameters of a function) are chosen by the caller of the function. They can be arbitrarily long, so if 'b is chosen to be e.g. 'static, that would imply that you just took a &'static reference to a local variable! This is clearly nonsensical.