Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Improve the documentation for rvalue_static_promotion
  • Loading branch information
tbg committed Mar 14, 2017
commit f06b04949f7944bfe31405d3735240bb02ee9bd1
18 changes: 18 additions & 0 deletions src/doc/unstable-book/src/rvalue-static-promotion.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion src/test/run-pass/rvalue-static-promotion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
fn main() {
let x: &'static u32 = &42;
let y: &'static Option<u32> = &None;
}
}