]> git.proxmox.com Git - rustc.git/blob - src/doc/unstable-book/src/language-features/infer-static-outlives-requirements.md
New upstream version 1.52.0~beta.3+dfsg1
[rustc.git] / src / doc / unstable-book / src / language-features / infer-static-outlives-requirements.md
1 # `infer_static_outlives_requirements`
2
3 The tracking issue for this feature is: [#54185]
4
5 [#54185]: https://github.com/rust-lang/rust/issues/54185
6
7 ------------------------
8 The `infer_static_outlives_requirements` feature indicates that certain
9 `'static` outlives requirements can be inferred by the compiler rather than
10 stating them explicitly.
11
12 Note: It is an accompanying feature to `infer_outlives_requirements`,
13 which must be enabled to infer outlives requirements.
14
15 For example, currently generic struct definitions that contain
16 references, require where-clauses of the form T: 'static. By using
17 this feature the outlives predicates will be inferred, although
18 they may still be written explicitly.
19
20 ```rust,ignore (pseudo-Rust)
21 struct Foo<U> where U: 'static { // <-- currently required
22 bar: Bar<U>
23 }
24 struct Bar<T: 'static> {
25 x: T,
26 }
27 ```
28
29
30 ## Examples:
31
32 ```rust,ignore (pseudo-Rust)
33 #![feature(infer_outlives_requirements)]
34 #![feature(infer_static_outlives_requirements)]
35
36 #[rustc_outlives]
37 // Implicitly infer U: 'static
38 struct Foo<U> {
39 bar: Bar<U>
40 }
41 struct Bar<T: 'static> {
42 x: T,
43 }
44 ```