Skip to content

Commit 130e3ab

Browse files
committed
add section in book
1 parent 3bc6bec commit 130e3ab

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# `infer_static_outlives_requirements`
2+
3+
The tracking issue for this feature is: [#44493]
4+
5+
[#44493]: https://github.com/rust-lang/rust/issues/44493
6+
7+
------------------------
8+
The `infer_static_outlives_requirements` feature indicates that certain
9+
`'static` outlives requirements can be infered 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 infered, 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+
```
45+

0 commit comments

Comments
 (0)