Skip to content

Commit f06b049

Browse files
committed
Improve the documentation for rvalue_static_promotion
1 parent 20c0f32 commit f06b049

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/doc/unstable-book/src/rvalue-static-promotion.md

+18
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,22 @@
22

33
The tracking issue for this feature is: [#38865]
44

5+
[#38865]: https://github.com/rust-lang/rust/issues/38865
6+
57
------------------------
8+
9+
The `rvalue_static_promotion` feature allows directly creating `'static` references to
10+
constant `rvalue`s, which in particular allowing for more concise code in the common case
11+
in which a `'static` reference is all that's needed.
12+
13+
14+
## Examples
15+
16+
```rust
17+
#![feature(rvalue_static_promotion)]
18+
19+
fn main() {
20+
let DEFAULT_VALUE: &'static u32 = &42;
21+
assert_eq!(*DEFAULT_VALUE, 42);
22+
}
23+
```

src/test/compile-fail/feature-gate-rvalue_static_promotion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
fn main() {
1313
let x: &'static u32 = &42; //~ error: does not live long enough
1414
let y: &'static Option<u32> = &None; //~ error: does not live long enough
15-
}
15+
}

src/test/run-pass/rvalue-static-promotion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
fn main() {
1515
let x: &'static u32 = &42;
1616
let y: &'static Option<u32> = &None;
17-
}
17+
}

0 commit comments

Comments
 (0)