Understanding Rust lifetime elision rules
This is an easy Rust language-knowledge question that tests your grasp of lifetime elision—the compiler's rules for inferring lifetimes automatically when they are not explicitly annotated. It appears frequently in Rust interviews because it separates candidates who have memorized the rules from those who understand them.
The question asks you to determine whether a given function signature will compile under Rust's elision rules. To answer it, you need to know which lifetime parameters the compiler can safely infer and which ones require explicit annotation. This tests both your understanding of how borrowing works and your familiarity with the specific heuristics Rust uses to reduce boilerplate.
- Input and output lifetime parameters
- Self lifetimes in methods
- Ambiguity and when elision fails