Summary
ConstructCoroutineInClosureShim (used for FnMut::call_mut / Fn::call dispatch on async closures) does not propagate #[track_caller], unlike ClosureOnceShim which has an explicit track_caller: bool field.
Location
compiler/rustc_middle/src/ty/instance.rs, line 311-323
Bug
pub fn requires_caller_location(&self, tcx: TyCt<'_>) -> bool {
match *self {
InstanceKind::Item(def_id)
| InstanceKind::Virtual(def_id, _)
| InstanceKind::VTableShim(def_id) => {
tcx.body_codegen_attrs(def_id).flags.contains(CodegenFnAttrFlags::TRACK_CALLER)
}
InstanceKind::ClosureOnceShim { track_caller, .. } => track_caller,
_ => false, // ConstructCoroutineInClosureShim falls here
}
}
ClosureOnceShim has track_caller: bool and checks it. ConstructCoroutineInClosureShim has no such field and returns false. If an async closure with #[track_caller] is called through dyn FnMut or dyn Fn (which goes through ConstructCoroutineInClosureShim), the caller location is lost.
Impact
Currently latent: both closure_track_caller (rust-lang#87417) and async_fn_track_caller (rust-lang#110011) are unstable feature gates. The bug would become user-facing when either feature stabilizes.
Fix
Add a track_caller: bool field to ConstructCoroutineInClosureShim and wire it through requires_caller_location.
Summary
ConstructCoroutineInClosureShim(used forFnMut::call_mut/Fn::calldispatch on async closures) does not propagate#[track_caller], unlikeClosureOnceShimwhich has an explicittrack_caller: boolfield.Location
compiler/rustc_middle/src/ty/instance.rs, line 311-323Bug
ClosureOnceShimhastrack_caller: booland checks it.ConstructCoroutineInClosureShimhas no such field and returnsfalse. If an async closure with#[track_caller]is called throughdyn FnMutordyn Fn(which goes throughConstructCoroutineInClosureShim), the caller location is lost.Impact
Currently latent: both
closure_track_caller(rust-lang#87417) andasync_fn_track_caller(rust-lang#110011) are unstable feature gates. The bug would become user-facing when either feature stabilizes.Fix
Add a
track_caller: boolfield toConstructCoroutineInClosureShimand wire it throughrequires_caller_location.