Skip to content

RS-LIFE0002 · demanded_static_lifetime

Count parameters and fields that demand data pinned for the whole run of the program.

This is a deterministic rule for rust. Read its implementation.

Report each 'static written as the lifetime of a reference a parameter takes or a field holds. A 'static reference does not say the data lives a long time. It says the data lives forever, which is a claim only a literal, a leak, or a global can honestly make, and demanding it of a caller is how the annotation wins an argument with the borrow checker by making the type unable to hold anything the caller owns.

Where the pin sits decides whether it costs anything. A parameter typed &'static str cannot be handed a name read from a file and a field typed the same way cannot store one, and neither limitation is visible at the call site until someone tries. A return typed &'static str is the opposite, since it promises the caller more than it had to, forecloses nothing, and is how a lookup table hands back a name without allocating. Only the demanding side is reported.

Continue with evidence and references, or open the examples.