rust/compiler/rustc_middle/src
bors fee0e668bc Auto merge of #121557 - RalfJung:const-fn-call-promotion, r=oli-obk
restrict promotion of `const fn` calls

We only promote them in `const`/`static` initializers, but even that is still unfortunate -- we still cannot add promoteds to required_consts. But we should add them there to make sure it's always okay to evaluate every const we encounter in a MIR body.  That effort of not promoting things that can fail to evaluate is tracked in https://github.com/rust-lang/rust/issues/80619. These `const fn` calls are the last missing piece.

So I propose that we do not promote const-fn calls in const when that may fail without the entire const failing, thereby completing https://github.com/rust-lang/rust/issues/80619. Unfortunately we can't just reject promoting these functions outright due to backwards compatibility. So let's see if we can find a hack that makes crater happy...

For the record, this is the [crater analysis](https://github.com/rust-lang/rust/pull/80243#issuecomment-751885520) from when I tried to entirely forbid this kind of promotion. It's a tiny amount of breakage and if we had a nice alternative for code like that, we could conceivably push it through... but sadly, inline const expressions are still blocked on t-lang concerns about post-monomorphization errors and we haven't yet figured out an implementation that can resolve those concerns. So we're forced to make progress via other means, such as terrible hacks like this.

Attempt one: only promote calls on the "safe path" at the beginning of a MIR block. This is the path that starts at the start block and continues via gotos and calls, but stops at the first branch. If we had imposed this restriction before stabilizing `if` and `match` in `const`, this would have definitely been sufficient...

EDIT: Turns out that works. :)
**Here's the t-lang [nomination comment](https://github.com/rust-lang/rust/pull/121557#issuecomment-1990902440).** And here's the [FCP comment](https://github.com/rust-lang/rust/pull/121557#issuecomment-2010306165).

r? `@oli-obk`
2024-04-23 22:51:01 +00:00
..
dep_graph Use a dyn Debug trait object instead of a closure. 2024-03-27 10:59:18 +00:00
hir Auto merge of #123468 - compiler-errors:precise-capturing, r=oli-obk 2024-04-16 11:22:35 +00:00
hooks Rollup merge of #124016 - DaniPopes:dedup-default-providers, r=lcnr 2024-04-16 21:41:26 +02:00
infer nits 2024-04-15 16:52:51 -04:00
middle Rollup merge of #124067 - RalfJung:weak-lang-items, r=davidtwco 2024-04-23 12:10:25 +02:00
mir filter required_consts during inlining 2024-04-23 23:02:54 +02:00
query Auto merge of #123992 - compiler-errors:no-has-typeck-results, r=jackh726 2024-04-23 04:13:33 +00:00
thir Track mutability of deref patterns 2024-04-20 15:59:54 +02:00
traits Auto merge of #124008 - nnethercote:simpler-static_assert_size, r=Nilstrieb 2024-04-18 09:47:45 +00:00
ty Auto merge of #123126 - oli-obk:feed_crate_num, r=davidtwco 2024-04-23 20:46:48 +00:00
util remove some ancient debug output, looks unused? 2024-04-13 11:30:48 +03:00
arena.rs Actually create ranged int types in the type system. 2024-04-08 12:02:19 +00:00
error.rs Rename DiagnosticMessage as DiagMessage. 2024-03-05 12:14:49 +11:00
lib.rs Stabilize generic NonZero. 2024-04-22 18:48:47 +02:00
lint.rs Guard decorate on when not to skip instead 2024-03-17 15:07:22 +00:00
macros.rs Remove unnecessary braces from span_bug 2024-03-21 11:24:24 -04:00
metadata.rs rustc_metadata: Remove Span from ModChild 2023-04-18 17:25:04 +03:00
tests.rs Remove outdated references to librustc_middle. 2024-01-05 16:34:52 +00:00
thir.rs Rollup merge of #122598 - Nadrieril:full-derefpats, r=matthewjasper 2024-04-23 17:25:15 +02:00
values.rs make Representability::Infinite carry ErrorGuaranteed 2024-03-14 20:52:13 +01:00