---
source: https://iinventedlight.com/library/notes/rust-lifetimes.md
title: "Rust lifetimes: keeping references valid"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT or Apache-2.0 (rust-lang/book; Copyright (c) 2010 The Rust Project Developers; https://github.com/rust-lang/book/blob/main/LICENSE-MIT); MIT or Apache-2.0 (rust-lang/rust-by-example; Copyright (c) 2014 Jorge Aparicio; https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT); prose restates or closely paraphrases cited source lines"
license_family: rust-mit
rule_check: "needs rule check (family not in auto-publish rule; check.mjs auto-approves only usgov and arxiv-ccby)"
attribution: "Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Validating References with Lifetimes - The Rust Programming Language, MIT or Apache-2.0 (rust-lang/book; Copyright (c) 2010 The Rust Project Developers; https://github.com/rust-lang/book/blob/main/LICENSE-MIT); Rust by Example, Lifetimes - Rust By Example, MIT or Apache-2.0 (rust-lang/rust-by-example; Copyright (c) 2014 Jorge Aparicio; https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: Rust"
tags: ['rust', 'lifetimes', 'borrow-checker']
sources:
  - id: S1
    title: "Validating References with Lifetimes - The Rust Programming Language"
    publisher: The Rust Programming Language
    url: https://doc.rust-lang.org/book/ch10-03-lifetime-syntax.html
    accessed: 2026-11-04
    license: "MIT or Apache-2.0 (rust-lang/book; Copyright (c) 2010 The Rust Project Developers; https://github.com/rust-lang/book/blob/main/LICENSE-MIT)"
  - id: S2
    title: "Lifetimes - Rust By Example"
    publisher: Rust by Example
    url: https://doc.rust-lang.org/rust-by-example/scope/lifetime.html
    accessed: 2026-11-04
    license: "MIT or Apache-2.0 (rust-lang/rust-by-example; Copyright (c) 2014 Jorge Aparicio; https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT)"
---
# Rust lifetimes: keeping references valid

**Answer:** Lifetimes ensure that references are valid as long as we need them to be. Every reference in Rust has a lifetime, which is the scope for which that reference is valid. (S1)

## Usually inferred

- Most of the time, lifetimes are implicit and inferred, just like most of the time, types are inferred. (S1)
- We must annotate lifetimes when the lifetimes of references could be related in a few different ways. (S1)
- Rust requires us to annotate the relationships using generic lifetime parameters to ensure that the actual references used at runtime will definitely be valid. (S1)

## What they prevent

- The main aim of lifetimes is to prevent dangling references, which would cause a program to reference data other than the data it's intended to reference. (S1)
- A lifetime is a construct the compiler (or more specifically, its borrow checker) uses to ensure all borrows are valid. (S2)

## Lifetimes versus scopes

- A variable's lifetime begins when it is created and ends when it is destroyed. (S2)
- While lifetimes and scopes are often referred to together, they are not the same. (S2)
- The borrow is valid as long as it ends before the lender is destroyed. (S2)

## Claims
- id: C1
  claim: Every Rust reference has a lifetime.
  source: S1
  evidence: "that every reference in Rust has a lifetime"
- id: C2
  claim: Most lifetimes are implicit and inferred.
  source: S1
  evidence: "Most of the time, lifetimes are implicit and inferred"
- id: C3
  claim: The borrow checker uses lifetimes to ensure borrows are valid.
  source: S2
  evidence: "A lifetime is a construct the compiler"
- id: C4
  claim: Lifetimes and scopes are not the same.
  source: S2
  evidence: "lifetimes and scopes are often referred to together, they are not the same."

## Sources
- [S1] Validating References with Lifetimes - The Rust Programming Language. The Rust Programming Language. https://doc.rust-lang.org/book/ch10-03-lifetime-syntax.html . License: MIT or Apache-2.0 (rust-lang/book; Copyright (c) 2010 The Rust Project Developers; https://github.com/rust-lang/book/blob/main/LICENSE-MIT). Accessed 2026-11-04.
- [S2] Lifetimes - Rust By Example. Rust by Example. https://doc.rust-lang.org/rust-by-example/scope/lifetime.html . License: MIT or Apache-2.0 (rust-lang/rust-by-example; Copyright (c) 2014 Jorge Aparicio; https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT). Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
