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
+13-14
Original file line number
Diff line number
Diff line change
@@ -69,22 +69,19 @@ declaration. We can thus be less conservative. This is called *explicit*
69
69
promotion.
70
70
71
71
Currently, the following are considered explicit promotion contexts:
72
-
*`#[rustc_args_required_const]` arguments and inline assembly `const` operands everywhere
72
+
*`#[rustc_args_required_const]` arguments and inline assembly `const` operands everywhere.
73
+
* Everything inside the bodies of `const` and `static` items. (Note: this is handled separately from "explicit contexts" in promotion analysis, but the effect is the same.)
73
74
74
-
In these contexts, we promote calls to arbitrary `const fn`. That is currently
75
-
the only difference.
75
+
In these contexts, we promote calls to arbitrary `const fn`.
There is one further special case for the bodies of `const` and `static` items; here we additionally promote union field accesses.
78
+
Both of these special cases can lead to promoting things that can fail to evaluate.
79
+
Currently, this works out because 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.
80
80
81
-
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.
82
-
We do this for all kinds of promotion.
81
+
[See below][static access] for another special case in promotion analysis:
82
+
accesses and references to statics are only promoted inside other statics.
83
83
84
-
For `const fn`, [this is a bug](https://github.com/rust-lang/rust/issues/75586).
85
-
86
-
For `const` and `static` items, this can lead to promoting things that can fail to evaluate.
87
-
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.
0 commit comments