`const` in `async fn` is evaluated twice when used across crates.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
dep/src/lib.rs
#![warn(long_running_const_eval)]
pub async fn has_const() {
const CONST: () = {
let mut i = 0;
while i < 10_000_000 {
i += 1;
}
};
CONST
}
src/lib.rs
#![warn(long_running_const_eval)]
pub async fn call() {
dep::has_const().await;
}
I expected rust to evaluate the const only once.
Instead, the long_running_const_eval fires when compiling the dep crate, and also fires again when compiling the dependent crate. This means that the const is evaluated at least twice, wasting compilation time.
(For some reason, it fired twice per crate, for a total of 4 times. I don't know why.)
This bug was discovered in https://github.com/rust-lang/rust/issues/148328, and filed here as a separate issue.
Meta
rustc --version --verbose:
rustc 1.93.0-nightly (d5419f1e9 2025-10-30)
binary: rustc
commit-hash: d5419f1e97b90741d51841f800d3c697c662567d
commit-date: 2025-10-30
host: x86_64-pc-windows-msvc
release: 1.93.0-nightly
LLVM version: 21.1.3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the two-crate example using dep/src/lib.rs and src/lib.rs, then compare the long_running_const_eval warnings and evaluation counts in each crate. Trace how const evaluation results are handled across the crate boundary; done means the const is evaluated once rather than repeatedly while preserving the warning behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100