From f06b04949f7944bfe31405d3735240bb02ee9bd1 Mon Sep 17 00:00:00 2001 From: Tobias Schottdorf Date: Sun, 12 Mar 2017 18:31:17 -0400 Subject: [PATCH] Improve the documentation for `rvalue_static_promotion` --- .../src/rvalue-static-promotion.md | 18 ++++++++++++++++++ .../feature-gate-rvalue_static_promotion.rs | 2 +- src/test/run-pass/rvalue-static-promotion.rs | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/doc/unstable-book/src/rvalue-static-promotion.md b/src/doc/unstable-book/src/rvalue-static-promotion.md index 3b654960c8e..2583d350ebe 100644 --- a/src/doc/unstable-book/src/rvalue-static-promotion.md +++ b/src/doc/unstable-book/src/rvalue-static-promotion.md @@ -2,4 +2,22 @@ The tracking issue for this feature is: [#38865] +[#38865]: https://github.com/rust-lang/rust/issues/38865 + ------------------------ + +The `rvalue_static_promotion` feature allows directly creating `'static` references to +constant `rvalue`s, which in particular allowing for more concise code in the common case +in which a `'static` reference is all that's needed. + + +## Examples + +```rust +#![feature(rvalue_static_promotion)] + +fn main() { + let DEFAULT_VALUE: &'static u32 = &42; + assert_eq!(*DEFAULT_VALUE, 42); +} +``` diff --git a/src/test/compile-fail/feature-gate-rvalue_static_promotion.rs b/src/test/compile-fail/feature-gate-rvalue_static_promotion.rs index 41dc282be41..f33d0a71481 100644 --- a/src/test/compile-fail/feature-gate-rvalue_static_promotion.rs +++ b/src/test/compile-fail/feature-gate-rvalue_static_promotion.rs @@ -12,4 +12,4 @@ fn main() { let x: &'static u32 = &42; //~ error: does not live long enough let y: &'static Option = &None; //~ error: does not live long enough -} \ No newline at end of file +} diff --git a/src/test/run-pass/rvalue-static-promotion.rs b/src/test/run-pass/rvalue-static-promotion.rs index f8d93783877..30643cfc3eb 100644 --- a/src/test/run-pass/rvalue-static-promotion.rs +++ b/src/test/run-pass/rvalue-static-promotion.rs @@ -14,4 +14,4 @@ fn main() { let x: &'static u32 = &42; let y: &'static Option = &None; -} \ No newline at end of file +}