-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Valid mutually recursive functions fail with E0391 at opt-level 2 and 3 #161234
Copy link
Copy link
Open
Labels
A-mir-optArea: MIR optimizationsArea: MIR optimizationsA-mir-opt-inliningArea: MIR inliningArea: MIR inliningC-bugCategory: This is a bug.Category: This is a bug.I-cycleIssue: A query cycle occurred while none was expectedIssue: A query cycle occurred while none was expectedI-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}Issue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}S-has-bisectionStatus: A bisection has been found for this issueStatus: A bisection has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Description
Metadata
Metadata
Assignees
Labels
A-mir-optArea: MIR optimizationsArea: MIR optimizationsA-mir-opt-inliningArea: MIR inliningArea: MIR inliningC-bugCategory: This is a bug.Category: This is a bug.I-cycleIssue: A query cycle occurred while none was expectedIssue: A query cycle occurred while none was expectedI-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}Issue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}S-has-bisectionStatus: A bisection has been found for this issueStatus: A bisection has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
I tried this code:
Compile it with:
The same problem also occurs with:
I expected to see this happen:
The program should compile successfully. Mutually recursive functions are valid Rust.
The program recurses indefinitely and will eventually overflow the stack if it is executed, but this runtime behavior should not prevent compilation.
Instead, this happened:
Compilation fails with E0391:
I tested the minimized reproducer with the latest stable and nightly toolchains available on 2026-08-17.
-C opt-level=0-C opt-level=1-C opt-level=2-C opt-level=3This is a minimized/reduced standalone test case.
The cycle appears to be in rustc's MIR optimization / cross-crate inlinability queries. Such an internal query cycle should not cause rustc to reject an otherwise valid Rust program.
Meta
Latest stable:
rustc --version --verbose:Latest nightly:
rustc +nightly --version --verbose:Backtrace
Not applicable: rustc does not panic. It reports E0391 and aborts compilation.