Skip to content

Commit cab4825

Browse files
committed
promotion tweaks
1 parent a71d34f commit cab4825

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

promotion.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,15 @@ Currently, non-`Copy` array initialization is treated as an implicit context,
6666
because the code could compile even without promotion (namely, if the result
6767
type is `Copy`).
6868

69-
The distinction between these two determines whether calls to arbitrary `const
70-
fn`s (those without `#[rustc_promotable]`) are promotable (see below). See
71-
[rust-lang/const-eval#19](https://github.com/rust-lang/const-eval/issues/19)
72-
for a thorough discussion of this. At present, this is the only difference
73-
between implicit and explicit contexts. The requirements for promotion in an
74-
implicit context are a superset of the ones in an explicit context.
69+
CTFE of implicitly promoted code must never fail to evaluate except of the
70+
run-time code also would have failed. This means we cannot permit calling
71+
arbitrary `const fn`, as we cannot predict if they are going to perform an
72+
["unconst" operation](const_safety.md). Thus, only functions marked
73+
`#[rustc_promotable]` are implicitly promotable (see below). See
74+
[rust-lang/const-eval#19](https://github.com/rust-lang/const-eval/issues/19) for
75+
a thorough discussion of this. At present, this is the only difference between
76+
implicit and explicit contexts. The requirements for promotion in an implicit
77+
context are a superset of the ones in an explicit context.
7578

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

@@ -204,7 +207,8 @@ not have decided to promote. It is the responsibility of `foo` to not fail this
204207
way when working with const-safe arguments.
205208

206209
For this reason, only `const fn` that were explicitly marked with the
207-
`#[rustc_promotable]` attribute are subject to promotion.
210+
`#[rustc_promotable]` attribute are subject to promotion. Those functions must
211+
be manually reviewed to never raise CTFE errors.
208212

209213
### Drop
210214

0 commit comments

Comments
 (0)