Description
Split out from #140600
I tried this code:
pub fn this_errors() {
const { panic!("in fn") } //<~ ERROR: evaluation of `this_errors::{constant#0}` failed
}
pub async fn this_compiles() {
const { panic!("in async") } // compiles
}
I expected to see this happen: both functions raise a const eval error (or at least both functions don't)
Instead, this happened: sync function raises const eval error, but the same function with an async
keyword doesn't.
This is surprising from a perspective of a language user who is not familiar with intricacies of async internals. I didn't expect that making function async would "disable" const checks.
And even though i kinda sorta know some details of async desugaring, it is still surprising that the following "sorta desugared" code does fail to compile (unlike non-desugared version) (I realize that this desugaring is very far from perfect, I'm only dabbling)
fn desugared() -> impl Fn() {
|| const { panic!("in closure") } //<~ ERROR
}
Meta
rustc --version --verbose
:
rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-pc-windows-msvc
release: 1.86.0
LLVM version: 19.1.7
I'm not sure if this current behavior is a bug per se or if it's only just a mildly surprising behaviour, but thought it's still worth making an issue either way.
@rustbot label: +T-compiler +T-lang +A-async-await +A-const-eval