rust-lang / rust-lang/rust

`#[track_caller]` on async closures silently do nothing unless `async_fn_track_caller` is enabled.

Open
#161,961 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-async-closures A-lints A-panic C-bug requires-nightly T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

#![feature(closure_track_caller)]

#[tokio::main]
async fn main() {
    let closure = {
        #[track_caller]
        async || {
            panic!();
        }
    };
    closure().await;
}

I expected either:

  • the ungated_async_fn_track_caller lint fires; or
  • the panic output points to the closure().await line (line 11)

Instead, no warning is given, and the panic output points to the panic!(); line (line 8):

thread 'main' (13) panicked at src/main.rs:8:13:
explicit panic
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Enabling the async_fn_track_caller feature causes the panic output to correctly point to line 11 instead.

The ungated_async_fn_track_caller lint (implemented in https://github.com/rust-lang/rust/pull/104741) is supposed to warn the user if a #[track_caller] doesn't do anything due to not enabling the async_fn_track_caller feature. It does not work properly here.

Tracking issue for closure_track_caller: https://github.com/rust-lang/rust/issues/87417

Tracking issue for async_fn_track_caller: https://github.com/rust-lang/rust/issues/110011

Meta

Reproducible on the playground with version 1.100.0-nightly (2026-08-26 bff8e12ff5e6bcd53dfb)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reduced async-closure example and inspect the ungated_async_fn_track_caller lint together with the closure_track_caller and async_fn_track_caller feature handling. Reproduce the missing warning without async_fn_track_caller enabled, then verify the fix makes the lint fire or produces the expected caller location.

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
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.