Skip to content

Commit 50a1829

Browse files
committed
link to the must-not-err RFC
1 parent a9c7047 commit 50a1829

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

promotion.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
# Const promotion
22

3-
["(Implicit) Promotion"][rfc] is a mechanism that affects code like `&3`:
3+
["(Implicit) Promotion"][promotion-rfc] is a mechanism that affects code like `&3`:
44
Instead of putting it on the stack, the `3` is allocated in global static memory
55
and a reference with lifetime `'static` is provided. This is essentially an
6-
automatic transformation turning `&EXPR` into `{ const _PROMOTED = &EXPR; EXPR
7-
}`, but only if `EXPR` qualifies.
6+
automatic transformation turning `&EXPR` into
7+
`{ const _PROMOTED = &EXPR; EXPR}`, but only if `EXPR` qualifies.
88

99
Note that promotion happens on the MIR, not on surface-level syntax. This is
1010
relevant when discussing e.g. handling of panics caused by overflowing
1111
arithmetic.
1212

1313
On top of what applies to [consts](const.md), promoteds suffer from the additional issue that *the user did not ask for them to be evaluated at compile-time*.
1414
Thus, if CTFE fails but the code would have worked fine at run-time, we broke the user's code for no good reason.
15+
Even if we are sure we found an error in the user's code, we are only allowed to [emit a warning, not a hard error][warn-rfc].
1516
That's why we have to be very conservative with what can and cannot be promoted.
1617

17-
[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1414-rvalue_static_promotion.md
18+
[promotion-rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1414-rvalue_static_promotion.md
19+
[warn-rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1229-compile-time-asserts.md
1820

1921
## Rules
2022

0 commit comments

Comments
 (0)