Rust
E0310 Type May Not Live Long Enough Fix
E0310 is about a type parameter, not a value: a struct or enum stores something that requires T to outlive 'static - most often a &'static T field - but T itself carries no such bound, so the type definition is rejected before any value is built. This guide works the shapes that produce E0310, shows the T: 'static repair the diagnostic itself proposes, shows the named-lifetime repair for when 'static is stronger than the design needs, and separates the neighbor E0309, where the missing bound is against a named lifetime instead.
Written November 30, 2026 · Tested with Rust 1.99.1 · 17 min read
- The rule underneath: a bound on T is a promise about everything inside T
- How to read the diagnostic
- The first failure: a &'static T field
- The same failure in an enum, a slice, a mutable reference, and a function pointer
Written November 30, 2026
Tested with Rust 1.99.1
What this guide is
Error E0310 is a missing lifetime bound on a type parameter. The error codes index opens with the cause - "A parameter type is missing a lifetime constraint or has a lifetime that does not live long enough" - and its erroneous example is the first failure in this guide: a struct Foo<T> whose only field is &'static T, with no bound on T. Its fix is the move this guide is built around: declare the constraint on the parameter, struct Foo<T: 'static>.
The distinction that decides whether you are in this guide or the neighboring one is which lifetime the bound is missing against. E0310 is the 'static case in every failing program in this guide: the field, the function pointer, or the applicable implementation requires the parameter to be valid for the static lifetime, and the type definition does not say so. The neighboring guide on E0309 covers the same sentence - "the parameter type may not live long enough" - for a named lifetime 'a, where the repair is T: 'a in a where clause or bound. This guide links that guide for the named-lifetime case and does not re-teach it; here the missing bound is against 'static, and the subject is the type parameter itself, not a borrowed value inside a function body.
The practical payoff is that E0310 is checked at the definition, not at a use site. Every failing program below fails with an empty main - no value of the type is ever constructed - because the definition alone is not well-formed: it promises to store data valid for 'static while accepting parameters that may not be.
Build every program in this guide with rustc --edition 2021. In the compiler transcripts below, the file names are the bare names shown on the command line.
The rule underneath: a bound on T is a promise about everything inside T
The Rust Reference's trait and lifetime bounds section defines the reading of the bound this error asks for: "T: 'a means that all lifetime parameters of T outlive 'a." A generic parameter is not necessarily a plain value - T can itself be a reference, or a struct containing references - so a field of type &'static T is only sound if every lifetime inside whatever T turns out to be is valid for 'static as well. That is what T: 'static states, and without it the definition has not established the thing its own field requires.
The same section explains why the neighboring shapes below behave differently: "Lifetime bounds are also inferred for type definitions and impl blocks for any type" - its example is a struct field &'a T, which "requires T: 'a to be well-formed, which is inferred by the compiler." In the probed set that inference covers a field referencing a named lifetime parameter of the definition itself, and it does not cover 'static: the &'static T field fails below while the &'a T field compiles with no explicit bound written. Likewise, lifetime bounds in function signatures are implied by the types appearing there, which is why the function program in the traps section compiles. In every failing program in this guide, the missing bound is one the definition had to state itself.
How to read the diagnostic
The header is fixed: "the parameter type T may not live long enough". The span points at the field type that imposes the requirement, and the labels under it come in two forms in this guide's probed set. For reference-shaped fields the pair is "the parameter type T must be valid for the static lifetime..." and "...so that the reference type &'static T does not outlive the data it points at", with the field's full type named in the second label. For the associated-type field the second label instead reads "...so that the type T will meet its required lifetime bounds", because the requirement arrives through an implementation's bound rather than through a reference in the field itself.
The help block is the same in every failing program in this guide: "consider adding an explicit lifetime bound", shown as an insertion on the definition line - struct Foo<T: 'static> {, with the inserted text underlined by +++++++++. Read it literally: the compiler is not asking you to change the field, shorten a borrow, or fix a call site. It is asking the definition to declare the bound its field already assumes. Whether 'static is the bound you actually want is the design question the fixes section takes up - the alternative repair keeps a named lifetime instead.
The first failure: a &'static T field
This is the error index's own example, as a complete program - a generic struct whose field is a static reference to the parameter, and nothing else:
struct Foo<T> {
foo: &'static T
}
fn main() {}
error[E0310]: the parameter type `T` may not live long enough
--> q1.rs:2:10
|
2 | foo: &'static T
| ^^^^^^^^^^
| |
| the parameter type `T` must be valid for the static lifetime...
| ...so that the reference type `&'static T` does not outlive the data it points at
|
help: consider adding an explicit lifetime bound
|
1 | struct Foo<T: 'static> {
| +++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0310`.
Nothing is borrowed anywhere in this program, and no Foo value exists. The definition alone is the problem: it would accept a T containing a short-lived reference and then store a &'static reference to it. The compiler rejects the definition rather than waiting for a construction that would expose the mismatch.
The same failure in an enum, a slice, a mutable reference, and a function pointer
The field's exact shape varies; the missing bound does not. An enum variant holding the same reference fails identically:
enum Choice<T> {
One(&'static T),
None,
}
fn main() {}
error[E0310]: the parameter type `T` may not live long enough
--> q2.rs:2:9
|
2 | One(&'static T),
| ^^^^^^^^^^
| |
| the parameter type `T` must be valid for the static lifetime...
| ...so that the reference type `&'static T` does not outlive the data it points at
|
help: consider adding an explicit lifetime bound
|
1 | enum Choice<T: 'static> {
| +++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0310`.
A field holding a static slice of the parameter - a reference to many T rather than one - fails the same way, and the second label names the slice type:
struct Foo<T> {
foo: &'static [T],
}
fn main() {}
error[E0310]: the parameter type `T` may not live long enough
--> q4.rs:2:10
|
2 | foo: &'static [T],
| ^^^^^^^^^^^^
| |
| the parameter type `T` must be valid for the static lifetime...
| ...so that the reference type `&'static [T]` does not outlive the data it points at
|
help: consider adding an explicit lifetime bound
|
1 | struct Foo<T: 'static> {
| +++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0310`.
Mutability changes nothing in the probed set. A &'static mut T field produces the same header, the same first label, and the same offered bound, with the mutable reference type named in the second label:
struct Foo<T> {
foo: &'static mut T,
}
fn main() {}
error[E0310]: the parameter type `T` may not live long enough
--> q7.rs:2:10
|
2 | foo: &'static mut T,
| ^^^^^^^^^^^^^^
| |
| the parameter type `T` must be valid for the static lifetime...
| ...so that the reference type `&'static mut T` does not outlive the data it points at
|
help: consider adding an explicit lifetime bound
|
1 | struct Foo<T: 'static> {
| +++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0310`.
And the reference does not have to be stored directly. A field whose type is a function pointer returning &'static T imposes the same requirement, because any function stored there hands out static references to T:
struct Foo<T> {
make: fn() -> &'static T,
}
fn main() {}
error[E0310]: the parameter type `T` may not live long enough
--> q6.rs:2:11
|
2 | make: fn() -> &'static T,
| ^^^^^^^^^^^^^^^^^^
| |
| the parameter type `T` must be valid for the static lifetime...
| ...so that the reference type `&'static T` does not outlive the data it points at
|
help: consider adding an explicit lifetime bound
|
1 | struct Foo<T: 'static> {
| +++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0310`.
In this guide's probed set, E0310 is one diagnostic for the whole family: struct or enum, shared, mutable, slice, or behind a function pointer - whenever a definition's field type requires the parameter to be valid for 'static and the parameter carries no such bound.
The associated-type form: the requirement arrives through an impl
A field does not have to mention a reference at all. Here the field's type is an associated-type projection, <T as Pick>::Output, and the only implementation of Pick requires T: 'static in its where clause. The struct does not declare that bound, so the projection is not known to be usable, and the definition fails - with E0310, because the impl's required bound is the static lifetime:
trait Pick {
type Output;
}
impl<T> Pick for T
where
T: 'static,
{
type Output = u32;
}
struct Foo<T> {
foo: <T as Pick>::Output,
}
fn main() {}
error[E0310]: the parameter type `T` may not live long enough
--> q3.rs:11:10
|
11 | foo: <T as Pick>::Output,
| ^^^^^^^^^^^^^^^^^^^
| |
| the parameter type `T` must be valid for the static lifetime...
| ...so that the type `T` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound
|
10 | struct Foo<T: 'static> {
| +++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0310`.
Note the second label: "so that the type T will meet its required lifetime bounds" instead of the reference wording. That wording is the tell that the requirement came from a bound somewhere else - here, the impl's where clause - rather than from a reference written in the field. The repair is the same declaration on the struct, and it is run in the fixes section. Hold this program next to the first trap below: the projection shape is identical there, but the impl requires a named lifetime, and the code is E0309 instead. In the probed set, the lifetime in the impl's requirement is what selects the code.
The traps: neighbors that are not E0310
The same associated-type projection against a named lifetime is E0309 - "the parameter type T may not live long enough" without the static requirement. This is the error index's E0309 example shape, and it is the neighboring guide's subject:
struct Foo<'a, T> {
foo: <T as SomeTrait<'a>>::Output,
}
trait SomeTrait<'a> {
type Output;
}
impl<'a, T> SomeTrait<'a> for T
where
T: 'a,
{
type Output = u32;
}
fn main() {}
error[E0309]: the parameter type `T` may not live long enough
--> n1.rs:2:10
|
1 | struct Foo<'a, T> {
| -- the parameter type `T` must be valid for the lifetime `'a` as defined here...
2 | foo: <T as SomeTrait<'a>>::Output,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound
|
1 | struct Foo<'a, T: 'a> {
| ++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0309`.
The headers differ by one word's worth of meaning: E0309's first label names the lifetime 'a "as defined here" and points back at the definition's own lifetime parameter, and its help inserts T: 'a, not T: 'static. If your diagnostic names a lifetime you declared, you are in E0309 territory - see the neighboring guide for its where-clause repair - not this guide's.
A field holding a reference to a named lifetime parameter of the same definition does not fail at all, because the bound that field needs is inferred for type definitions. This program compiles and runs with no explicit bound on T anywhere:
struct Foo<'a, T> {
foo: &'a T,
}
fn main() { let x = 42; let f = Foo { foo: &x }; println!("{}", f.foo); }
42
The output is 42. Do not read this as "&'a T fields never need bounds": it is the definition-with-a-lifetime-parameter shape that compiles in this guide's probed set, and the E0309 program above shows a field in just such a definition failing when the requirement arrives through an impl instead of through the reference itself.
A function signature mentioning &'static T also does not fail. Lifetime bounds in a signature are implied by the types appearing in it, so this function needs no written bound and the call runs:
fn show<T>(x: &'static T) -> &'static T { x }
fn main() { println!("{}", show(&42)); }
42
The output is 42. The contrast with the first failure is the position of the reference: inside a function signature the bound is implied, while inside a type definition's field - in every failing program in this guide - the 'static bound had to be declared on the parameter. If your E0310 span points at a struct or enum field, adding bounds to functions will not touch it.
Last, a trait-object field over the parameter did not produce E0310 in the probed set. This struct stores a Box<dyn Iterator<Item = T>> with no bound on T, and it compiles and runs:
struct Foo<T> {
foo: Box<dyn Iterator<Item = T>>,
}
fn main() { let mut f = Foo { foo: Box::new(vec![1, 2, 3].into_iter()) }; println!("{}", f.foo.by_ref().sum::<i32>()); }
6
The output is 6, the sum of the stored iterator's items. Do not generalize this past the probed shape: it shows that this trait-object field, as written, is not one of the shapes that emits E0310 in this guide - not that trait objects never impose lifetime requirements on a parameter.
Fixes in reach order
First, take the diagnostic's own repair when 'static is genuinely what the type means: declare T: 'static on the definition. The first failure, repaired exactly as its help proposes, compiles and runs:
struct Foo<T: 'static> {
foo: &'static T,
}
fn main() { let f = Foo { foo: &42 }; println!("{}", f.foo); }
42
The output is 42. The bound does not change what the struct stores; it narrows which types may fill T to those valid for the static lifetime - owned types and types containing only static references, in the usual case - which is exactly the set the field was already assuming. The same declaration repairs the enum:
enum Choice<T: 'static> {
One(&'static T),
None,
}
fn main() { let c = Choice::One(&42); match c { Choice::One(v) => println!("{}", v), Choice::None => println!("none"), } }
42
The output is 42, read back out of the One variant. The slice field takes the same bound:
struct Foo<T: 'static> {
foo: &'static [T],
}
fn main() { let f = Foo { foo: &[10, 20] }; println!("{}", f.foo[1]); }
20
The output is 20, the second element of the stored slice. And the function-pointer field:
fn answer() -> &'static i32 { &42 }
struct Foo<T: 'static> {
make: fn() -> &'static T,
}
fn main() { let f = Foo::<i32> { make: answer }; println!("{}", (f.make)()); }
42
The output is 42, produced by calling the stored function pointer. In each of these fixes the only change from its failing counterpart is the bound on the parameter - the field types are untouched, because the fields were never the problem.
The associated-type failure takes the same declaration. Adding T: 'static to the struct states the bound the Pick implementation requires, and the projection becomes usable:
trait Pick {
type Output;
}
impl<T> Pick for T
where
T: 'static,
{
type Output = u32;
}
struct Foo<T: 'static> {
foo: <T as Pick>::Output,
}
fn main() { let f = Foo::<i32> { foo: 7 }; println!("{}", f.foo); }
7
The output is 7, the value stored through the projection type. An equivalent spelling is a where clause on the definition - struct Foo<T> where T: 'static { ... } - which states the same bound; the inline form is the one the diagnostic offers and the one used in this guide's fixes.
Second, when 'static is stronger than the design needs, do not pay for it: give the definition its own lifetime parameter and bound T against that instead. This is the repair to reach for when the stored reference only has to live as long as some borrow the caller already has:
struct Foo<'a, T: 'a> {
foo: &'a T,
}
fn main() { let x = 42; let f = Foo { foo: &x }; println!("{}", f.foo); }
42
The output is 42, read from a reference to a local variable - a value no T: 'static version of this struct could have stored a reference to, because x does not live for the static lifetime. Choosing between the two repairs is the real decision E0310 puts in front of you: T: 'static keeps the field as written and restricts the parameter; a named 'a with T: 'a keeps the parameter general and ties the stored reference to a lifetime the caller supplies. In the probed set both compile and run; which one is correct is a property of what the type is for, not of the diagnostic.
Last, if the diagnostic is not E0310 at all, switch playbooks: a missing bound against a named lifetime is E0309 (see the neighboring guide), and a definition whose field references a named lifetime parameter may need no change at all, as the traps section shows.
Decision summary
E0310, "the parameter type may not live long enough", is one shape in this guide's probed set: a struct or enum definition whose field type requires its type parameter to be valid for the static lifetime - a &'static T, &'static mut T, or &'static [T] field, a function pointer returning &'static T, or an associated-type projection whose implementation requires T: 'static - while the parameter declares no such bound. The failure is at the definition, with no value constructed. The diagnostic names the static lifetime in its labels and offers T: 'static as an insertion on the definition line. The repairs declare the bound the field assumes: T: 'static when the static lifetime is genuinely required, or a named lifetime parameter with T: 'a - and the field retyped to &'a T - when it is not. The neighbors are distinct: the same projection against a named lifetime is E0309, a &'a T field in a definition with that lifetime parameter compiles with the bound inferred, a function signature taking &'static T compiles with the bound implied, and a Box<dyn Iterator<Item = T>> field did not emit E0310 in the probed set.
Checklist
- Check which lifetime the labels name: the static lifetime is E0310; a named lifetime you declared is E0309.
- Read the second label - reference wording means the field itself imposes the bound; "will meet its required lifetime bounds" means an impl's bound does.
- Add the bound to the type parameter on the definition, not to a function or a call site.
- Choose deliberately:
T: 'staticrestricts the parameter; a named'awithT: 'arestricts the stored reference instead. - Do not add
T: 'staticto silence the error when callers need to store references to locals - retype the field with a named lifetime. - Do not expect inference to cover
'staticin a type definition - in the probed set it covered the named-lifetime field and the function signature, and not the static field.
Related guides on this site
- E0309 Type May Not Live Long Enough Fix
- Fix Rust E0597 "`x` does not live long enough" — a Block Scope, a Stored Reference, a Struct Field, and a Closure Capture
- E0091 Unused Type Parameter Fix
- E0210 Type Parameter Orphan Rule Fix
Sources
- Rust error codes index, E0310 - a parameter type is missing a lifetime constraint or has a lifetime that does not live long enough; the erroneous example with a
&'static Tfield and no bound onT; the fix of adding the constraintT: 'staticto the type parameter. - Rust error codes index, E0309 - a parameter type is missing an explicit lifetime bound against a named lifetime; the associated-type projection example and the repair of adding a where clause
T: 'ato the struct definition. - The Rust Reference, Trait and lifetime bounds -
T: 'ameans all lifetime parameters ofToutlive'a; lifetime bounds are implied by function signatures, and inferred for type definitions and impl blocks, with the&'a Tfield example whoseT: 'arequirement is inferred by the compiler.
Keep Exploring
The full Rust hub \u2014 ownership, structs and enums, async, and measured comparisons.
Every guide on the site in one list, grouped by topic.
Every browser-only checker and verifier on the site.
The C++, Python, Sysadmin, Rust, Go, and TypeScript hubs.