You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: promotion.md
+12-7
Original file line number
Diff line number
Diff line change
@@ -100,17 +100,22 @@ promotion.
100
100
101
101
Currently, the following are considered explicit promotion contexts:
102
102
*`#[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
105
103
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
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
+
114
119
## Promotability
115
120
116
121
We have described the circumstances where promotion is desirable, but what
0 commit comments