]> git.proxmox.com Git - rustc.git/blame - src/librustc_error_codes/error_codes/E0310.md
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0310.md
CommitLineData
74b04a01
XL
1A parameter type is missing a lifetime constraint or has a lifetime that
2does not live long enough.
3
4Erroneous code example:
60c5eb7d
XL
5
6```compile_fail,E0310
7// This won't compile because T is not constrained to the static lifetime
8// the reference needs
9struct Foo<T> {
10 foo: &'static T
11}
12```
13
74b04a01
XL
14Type parameters in type definitions have lifetimes associated with them that
15represent how long the data stored within them is guaranteed to live. This
16lifetime must be as long as the data needs to be alive, and missing the
17constraint that denotes this will cause this error.
18
60c5eb7d
XL
19This will compile, because it has the constraint on the type parameter:
20
21```
22struct Foo<T: 'static> {
23 foo: &'static T
24}
25```