`'static`
'static is the lifetime that lasts for the rest of the program. String literals are &'static str. A spawned thread's captures must be 'static because the thread may outlive the stack that created it.
Detailed Explanation
'static does not mean "this is a global". It means "this reference is valid until the process ends". A string literal, "ada", lives in the binary's read-only data and is 'static. A const item is 'static. A static item is 'static and has a fixed address.
Box::leak can produce a 'static reference by never freeing the box. That is a real leak, used for data that should live until exit. It is not a way to "upgrade" a local. A local String dropped at the end of the function is not 'static, and no cast will make it so without leaking or lying (transmute of a shorter lifetime is UB).
'static as a bound, T: 'static, means T does not contain any non-static borrow. String is 'static. i32 is 'static. &'a str is only 'static if 'a is. thread::spawn and tokio::spawn require 'static so the task can outlive the current frame. The bound is about the data not dangling, not about the data being a literal.
People write 'static on trait objects, Box<dyn Error + 'static>, to say the erased value owns everything it needs. That is the usual error-type bound. A trait object that borrows, dyn Debug + 'a, is valid too and is shorter-lived.
When you write 'static: literals, leaked memory, spawn bounds, trait objects that must own. When you do not: a local borrow. If the compiler asks for 'static and you have a local, clone or Arc the data; do not transmute.
A static mut is almost never the right 'static data. It is unsafe to read or write, it is a global, and it races. Prefer OnceLock, Mutex, or lazy-static replacements in std. 'static bounds on spawned tasks are satisfied by owned Strings and Arcs, not by reaching for static mut to silence the checker.
Code Examples
fn describe(s: &'static str) {
println!("{s}");
}
fn main() {
describe("ada"); // prints: ada
let owned = String::from("grace");
// describe(&owned); // would not compile: owned is not 'static
println!("{owned}"); // prints: grace
}Common Gotchas
A local `String` is not `'static`
Passing `&owned` to a `'static` parameter does not compile. Move the `String`, leak it, or change the parameter's lifetime.
Spawn bounds are `'static` because of outliving
`thread::scope` exists so you can borrow locals in threads that are joined before the locals die.