Skip to content

Commit

Permalink
tweak enclosing scope discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 17, 2020
1 parent 4854f41 commit 8d2506c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions promotion.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ the only difference.

## Promotion in const contexts

When promoting inside a const context (`const` and `static` items and `const fn`), we relax almost all promotion restrictions, except for basic constness restrictions (such as interior mutability or `Drop`).
When promoting inside a const context (`const` and `static` items and `const fn`), we relax almost all promotion restrictions, except for basic constness restrictions listed below.
We do this for all kinds of promotion.

For `const fn`, [this is a bug](https://github.com/rust-lang/rust/issues/75586).
Expand All @@ -101,7 +101,13 @@ the "enclosing scope", similar to how `let x = &mut x;` creates a reference
whose lifetime lasts for the enclosing scope. This is decided during MIR
building already, and does not involve lifetime extension.

This is also sometimes called "outermost scope" rule.
In contrast, this does not compile:

```rust
const OPT_EMPTY_BYTES: Option<&Vec<u8>> = Some(&Vec::new());
```

The "enclosing scope" rule only fires for outermost `&`, just like in `fn` bodies.

## Promotability

Expand Down

0 comments on commit 8d2506c

Please sign in to comment.