diff options
| author | Tobias Schottdorf <tobias.schottdorf@gmail.com> | 2017-03-12 18:31:17 -0400 |
|---|---|---|
| committer | Tobias Schottdorf <tobias.schottdorf@gmail.com> | 2017-03-14 11:06:50 -0400 |
| commit | f06b04949f7944bfe31405d3735240bb02ee9bd1 (patch) | |
| tree | ca7f76936244afd268badd92a90a7c97fd8617df | |
| parent | 20c0f323fc26fb913256301e242f34bccc788e31 (diff) | |
| download | rust-f06b04949f7944bfe31405d3735240bb02ee9bd1.tar.gz rust-f06b04949f7944bfe31405d3735240bb02ee9bd1.zip | |
Improve the documentation for `rvalue_static_promotion`
| -rw-r--r-- | src/doc/unstable-book/src/rvalue-static-promotion.md | 18 | ||||
| -rw-r--r-- | src/test/compile-fail/feature-gate-rvalue_static_promotion.rs | 2 | ||||
| -rw-r--r-- | 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<u32> = &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<u32> = &None; -} \ No newline at end of file +} |
