]> git.lizzy.rs Git - rust.git/commitdiff
add section in book
authortoidiu <apoorv@toidiu.com>
Fri, 27 Jul 2018 14:18:06 +0000 (10:18 -0400)
committertoidiu <apoorv@toidiu.com>
Fri, 27 Jul 2018 14:18:06 +0000 (10:18 -0400)
src/doc/unstable-book/src/language-features/infer-static-outlives-requirements.md [new file with mode: 0644]

diff --git a/src/doc/unstable-book/src/language-features/infer-static-outlives-requirements.md b/src/doc/unstable-book/src/language-features/infer-static-outlives-requirements.md
new file mode 100644 (file)
index 0000000..f50472f
--- /dev/null
@@ -0,0 +1,45 @@
+# `infer_static_outlives_requirements`
+
+The tracking issue for this feature is: [#44493]
+
+[#44493]: https://github.com/rust-lang/rust/issues/44493
+
+------------------------
+The `infer_static_outlives_requirements` feature indicates that certain
+`'static` outlives requirements can be infered by the compiler rather than
+stating them explicitly.
+
+Note: It is an accompanying feature to `infer_outlives_requirements`,
+which must be enabled to infer outlives requirements.
+
+For example, currently generic struct definitions that contain
+references, require where-clauses of the form T: 'static. By using
+this feature the outlives predicates will be infered, although
+they may still be written explicitly.
+
+```rust,ignore (pseudo-Rust)
+struct Foo<U> where U: 'static { // <-- currently required
+    bar: Bar<U>
+}
+struct Bar<T: 'static> {
+    x: T,
+}
+```
+
+
+## Examples:
+
+```rust,ignore (pseudo-Rust)
+#![feature(infer_outlives_requirements)]
+#![feature(infer_static_outlives_requirements)]
+
+#[rustc_outlives]
+// Implicitly infer U: 'static
+struct Foo<U> {
+    bar: Bar<U>
+}
+struct Bar<T: 'static> {
+    x: T,
+}
+```
+