+ ‘outlives seems unnecessary- always

⚓ rust    📅 2025-05-18    👤 surdeus    👁️ 5      

surdeus

Warning

This post was published 43 days ago. The information described in this article may have changed.

I’ve been trying to understand why the lifetime + ‘outlives in the return position impl Trait + ‘outlives annotation was ever required.

In the 2024 edition the “opaque” type captures all of the lifetimes in scope. That ensures the opaque type lifetime does not exceed that of the refs it depends on. No lifetime annotations required to capture the dependency. Got it.

In the 2021 edition: I don’t see any possible scenario where the hidden type could ever compile using a ref that wasn’t tied to the input ref lifetimes. I.e., the compiler would always ensure we return a ref that isn’t dangling. This holds without having to analyze the implementation of the trait. So why did we need this + outlives annotation?

Is this a case of “Rust prefers explicit” going wrong by logically implying the possibility of the impossible? Or am I missing a semantic understanding of the annotation?

See the RFC that discusses the topic. I wonder if the RFC would benefit from explicitly saying - “we were wrong to require the annotation because it is already part of what the compiler guarantees”.

3 posts - 2 participants

Read full topic

🏷️ rust_feed