Repository navigation
Description
I want to create a const &str based on the current location, but compilation fails with an out of bounds exception.
The following is a minimal reproduction for the core problem: The &str returned by std::panic::Location::caller().file() sometimes is the full path for const evaluation with async.
pub async fn async_example() {
const LOCATION: &std::panic::Location = std::panic::Location::caller();
const FILE: &str = LOCATION.file();
// (expected) evaluation panicked: dependency/src/lib.rs
// const VALUE: () = panic!("{}", FILE);
// (unexpected) evaluation panicked: /Users/anton.wetzel/projects/locate_what/dependency/src/lib.rs
const LENGTH: usize = FILE.len();
const VALUE: &str = in_sync::<LENGTH>(FILE);
println!("{:?}", VALUE);
}
pub const fn in_sync<const N: usize>(file: &str) -> &str {
if N != file.len() {
panic!("{}", file);
}
// create a [u8; N] and fill it with the chars or something similar...
file
}I expected no panic, because N is the length of FILE.
Instead, the function is evaluated with the length of the relative file name as N and the complete file name as file.
Without the panic! Value is the relative name in the compiled binary.
If the function is not async, the problem does not occur.
If the function is not a dependency, the problem does not occur.
The complete reproduction: https://github.com/antonWetzel/locate_what
Meta
rustc --version --verbose:
rustc 1.91.0 (f8297e351 2025-10-28)
binary: rustc
commit-hash: f8297e351a40c1439a467bbbb6879088047f50b3
commit-date: 2025-10-28
host: aarch64-apple-darwin
release: 1.91.0
LLVM version: 21.1.2
rustc +nightly --version --verbose:
rustc 1.93.0-nightly (d5419f1e9 2025-10-30)
binary: rustc
commit-hash: d5419f1e97b90741d51841f800d3c697c662567d
commit-date: 2025-10-30
host: aarch64-apple-darwin
release: 1.93.0-nightly
LLVM version: 21.1.3
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsCompleted
Activity
theemathas commentedon Oct 31, 2025
Inside the
in_syncfunction, changing the!=to==causes the code to panic with a different value forfile. It seems like theVALUEconst is being evaluated twice, with two different values forFILE.pitust commentedon Oct 31, 2025
You can reproduce this without async:
51 remaining items
Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco