Skip to content

Commit 179b4b6

Browse files
Rollup merge of #144756 - WaffleLapkin:inf-rec-etc-ctfe, r=lqd
detect infinite recursion with tail calls in ctfe fixes #144753
2 parents 7e8ef3a + 5aec437 commit 179b4b6

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

compiler/rustc_mir_transform/src/ctfe_limit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl<'tcx> crate::MirPass<'tcx> for CtfeLimit {
1818
.basic_blocks
1919
.iter_enumerated()
2020
.filter_map(|(node, node_data)| {
21-
if matches!(node_data.terminator().kind, TerminatorKind::Call { .. })
21+
if matches!(node_data.terminator().kind, TerminatorKind::Call { .. } | TerminatorKind::TailCall { .. })
2222
// Back edges in a CFG indicate loops
2323
|| has_back_edge(doms, node, node_data)
2424
{
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(explicit_tail_calls)]
2+
#![expect(incomplete_features)]
3+
4+
const _: () = f();
5+
6+
const fn f() {
7+
become f(); //~ error: constant evaluation is taking a long time
8+
}
9+
10+
fn main() {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: constant evaluation is taking a long time
2+
--> $DIR/infinite-recursion-in-ctfe.rs:7:5
3+
|
4+
LL | become f();
5+
| ^^^^^^^^^^
6+
|
7+
= note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
8+
If your compilation actually takes a long time, you can safely allow the lint.
9+
help: the constant being evaluated
10+
--> $DIR/infinite-recursion-in-ctfe.rs:4:1
11+
|
12+
LL | const _: () = f();
13+
| ^^^^^^^^^^^
14+
= note: `#[deny(long_running_const_eval)]` on by default
15+
16+
error: aborting due to 1 previous error
17+

0 commit comments

Comments
 (0)