Skip to content

Commit 9d16e3a

Browse files
committed
adjust docs to reality
1 parent aef9b00 commit 9d16e3a

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

promotion.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,22 @@ promotion.
100100

101101
Currently, the following are considered explicit promotion contexts:
102102
* `#[rustc_args_required_const]` arguments and inline assembly `const` operands everywhere
103-
* lifetime extension in the bodies of `const` and `static` items and array lengths
104-
* lifetime extension in the bodies of `const fn` -- but this is not justified by the above discussion; since `const fn` can be runtime-evaluated, the concerns about introducing hard errors where there would be none apply for `const fn` in exactly the same way as for `fn`, but this was overlooked when implementing the checks
105103

106-
Everything else is an implicit promotion context, in particular non-`Copy` array initializers.
107-
108-
In an explicit promotion context, we consider almost everything promotable,
109-
subject to the usual restrictions of [consts](const.md). This means that
110-
interior mutability and values that need dropping are not promoted.
104+
In these contexts, we promote calls to arbitrary `const fn`. That is currently
105+
the only difference.
111106

112107
[warn-rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1229-compile-time-asserts.md
113108

109+
## Promotion in const contexts
110+
111+
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`).
112+
We do this for all kinds of promotion.
113+
114+
For `const fn`, [this is a bug](https://github.com/rust-lang/rust/issues/75586).
115+
116+
For `const` and `static` items, this can lead to promoting things that can fail to evaluate.
117+
Currently, this works out because in the first case it just leads to a warning, but longer-term it would be desirable to turn evaluation failures into hard errors, which for these promoteds means we have to guarantee that we only evaluate them on-demand.
118+
114119
## Promotability
115120

116121
We have described the circumstances where promotion is desirable, but what

0 commit comments

Comments
 (0)