Skip to content

Commit 4e7e22b

Browse files
committed
less contrived example
1 parent 417088a commit 4e7e22b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

promotion.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,17 @@ restrictions described above still apply for the *result* of the promoted
232232
computation: in particular, it must be a valid `const` (i.e., it cannot
233233
introduce interior mutability) and it must not require dropping.
234234

235-
For instance, while the previous example was not legal, the following would be:
235+
For instance the following would be legal even though calls to `do_it` are not
236+
eligible for implicit promotion:
236237

237238
```rust
238-
const BOOL: i32 = {
239-
let ret = if cfg!(windows) { 0 } else { 1 };
239+
const fn do_it(x: i32) -> i32 { 2*x }
240+
const ANSWER: i32 = {
241+
let ret = do_it(21);
240242
ret
241243
};
242244

243-
let x: &'static i32 = &BOOL;
245+
let x: &'static i32 = &ANSWER;
244246
```
245247

246248
An access to a `static` is only promotable within the initializer of another

0 commit comments

Comments
 (0)