Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ github-issue: 2804
spec-path: docs/issues/open/2804-location-caller-track-caller-audit/ISSUE.md
branch: "2804-location-caller-track-caller-audit-spec"
related-pr: null
last-updated-utc: "2026-11-10 14:25"
last-updated-utc: "2026-11-10 21:51"
semantic-links:
skill-links:
- create-issue
Expand Down Expand Up @@ -206,9 +206,9 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`.

| ID | Status | Task | Notes / Expected Output |
| --- | ------ | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| T1 | TODO | Inventory and classify every site | Issue-local `inventory.md` with one row per `Location::caller()`/`#[track_caller]`/`Located(..).into()`: package, file:line, enclosing fn (async, closure, trait impl), test or production, class (correct/wrong/internal). Includes the small experiments on `parse`, async fn, closures and `Located::into`. |
| T2 | TODO | Trace production exposure | For each wrong site, the path to output (HTTP failure reason, UDP error message, REST API, CLI, logs, metrics, events), with the exact line that formats it. Mark "user-visible" or "developer-only". |
| T3 | TODO | Check guidance and enforceability | What the skill, ADRs, `Cargo.toml` lints and clippy config say. Is there a clippy lint (candidates: none known for this; verify) or a test that can enforce the rule? Record the answer even if "no". |
| T1 | DONE | Inventory and classify every site | Issue-local `inventory.md` with one row per `Location::caller()`/`#[track_caller]`/`Located(..).into()`: package, file:line, enclosing fn (async, closure, trait impl), test or production, class (correct/wrong/internal). Includes the small experiments on `parse`, async fn, closures and `Located::into`. |
| T2 | DONE | Trace production exposure | For each wrong site, the path to output (HTTP failure reason, UDP error message, REST API, CLI, logs, metrics, events), with the exact line that formats it. Mark "user-visible" or "developer-only". |
| T3 | DONE | Check guidance and enforceability | What the skill, ADRs, `Cargo.toml` lints and clippy config say. Is there a clippy lint (candidates: none known for this; verify) or a test that can enforce the rule? Record the answer even if "no". |
| T4 | TODO | Analyse fix options, recommend one | See options below; semver impact per published crate; recommended option with reasoning. Maintainer approves before any fix. |
| T5 | TODO | Write the ADR and the slicing plan | ADR if the convention changes. Create sub-issues or fix PRs per package from the slicing below. |
| T6 | TODO | Red regression tests per slice | For each slice (primitives; http-protocol, http-core, axum-http-server; tracker-core and database drivers; udp-server, axum-server, configuration and the rest from T1), a maintained test that fails against current code, with the red output recorded. Primitives first: `PeerRole`, `peer::Id` through `parse`/`try_into`; this closes the reported finding F3. |
Expand Down Expand Up @@ -287,6 +287,8 @@ with the narrow affected scope, and sign every commit with GPG.
- 2026-11-10 13:45 UTC - Claude Code (Sonnet 5.5) - Corrected the UDP exposure analysis after review F1.
- 2026-11-10 13:50 UTC - Claude Code (Sonnet 5.5) - Addressed review round 1 (F1-F9 and Copilot): recorded the reproduction, split the red/fix/green tasks, restored template passages, corrected facts and wording. Evidence: `manual-verification-evidence.md`.
- 2026-11-10 14:25 UTC - Claude Code (Sonnet 5.5) - Addressed review round 2 (F10-F16): UDP paths, timestamps, evidence numbering, audit record `docs/pr-reviews/pr-2805-review/PR-REVIEW.md`.
- 2026-11-10 17:49 UTC - Claude Code (Sonnet 5.5) - T1 to T3 done: `inventory.md` (classification, experiments, exposure trace, guidance and enforceability check).
- 2026-11-10 21:51 UTC - Claude Code (Sonnet 5.5) - Reworked the T2 trace, the closure and class columns, the standalone-crate scan and the experiment record after review of PR #2814 (`experiments.md`).

## Acceptance Criteria

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
---
doc-type: issue-experiments
issue-spec: docs/issues/open/2804-location-caller-track-caller-audit/ISSUE.md
last-updated-utc: "2026-11-10 21:51"
---

# Experiments E1 to E12: where `Location::caller()` reports what

Programs, commands and output behind the table in [`inventory.md`](inventory.md). Toolchain: stable
`rustc 1.99.1 (58cf8f9c3 2026-10-13)`, `cargo 1.99.1`, on Linux x86_64. `torrust-located-error` 3.0.0.

## E1 to E8: plain `rustc`

Command (one file, no dependencies): `rustc --edition 2021 track_caller_shapes.rs -o shapes && ./shapes`.

```rust
use std::future::Future;
use std::panic::Location;

#[track_caller]
fn loc() -> &'static Location<'static> {
Location::caller()
}

fn helper() -> &'static Location<'static> {
loc()
}

fn via_closure() -> &'static Location<'static> {
let f = || loc();
f()
}

fn via_map() -> &'static Location<'static> {
Some(1).map(|_| loc()).unwrap()
}

trait Tr {
fn m(&self) -> &'static Location<'static>;
}
struct S;
impl Tr for S {
#[track_caller]
fn m(&self) -> &'static Location<'static> {
Location::caller()
}
}
fn generic<X: Tr>(x: &X) -> &'static Location<'static> {
x.m()
}

#[track_caller]
const fn const_tc() -> &'static Location<'static> {
Location::caller()
}

#[track_caller]
async fn async_tc() -> &'static Location<'static> {
Location::caller()
}

fn main() {
println!("E1 direct call of a track_caller fn : {}", loc());
println!("E2 helper without track_caller : {}", helper());
println!("E3 closure calling a track_caller fn : {}", via_closure());
println!("E4 map(|_| loc()) : {}", via_map());
println!("E5 track_caller trait impl, direct call : {}", S.m());
println!("E6 same method through a generic bound : {}", generic(&S));
println!("E7 track_caller const fn : {}", const_tc());
let waker = std::task::Waker::noop();
let mut cx = std::task::Context::from_waker(waker);
let mut fut = Box::pin(async_tc());
if let std::task::Poll::Ready(l) = fut.as_mut().poll(&mut cx) {
println!("E8 track_caller async fn : {l}");
}
}
```

Compiler output: `warning: #[track_caller] on async functions is a no-op` (lint
`ungated_async_fn_track_caller`). Program output:

```text
E1 direct call of a track_caller fn : track_caller_shapes.rs:47:63
E2 helper without track_caller : track_caller_shapes.rs:10:5
E3 closure calling a track_caller fn : track_caller_shapes.rs:14:16
E4 map(|_| loc()) : track_caller_shapes.rs:19:21
E5 track_caller trait impl, direct call : track_caller_shapes.rs:51:65
E6 same method through a generic bound : track_caller_shapes.rs:33:7
E7 track_caller const fn : track_caller_shapes.rs:53:63
E8 track_caller async fn : track_caller_shapes.rs:43:5
```

Reading: E1, E5 and E7 report the line of the call in `main` (47, 51 and 53). E2, E3, E4 and E6
report a line inside the intermediate function or closure (10, 14, 19, 33). E8 reports line 43,
inside the `async fn` body, so the attribute does nothing.

## E9 to E12: `torrust-located-error`

Command: the program below was placed as `packages/configuration/tests/located_error_shapes.rs`
(deleted after the run) and run with
`cargo test -p torrust-tracker-configuration --test located_error_shapes -- --nocapture`.

```rust
use std::sync::Arc;

use torrust_located_error::{DynError, Located, LocatedError};

#[derive(Debug, thiserror::Error)]
#[error("boom")]
struct Boom;

fn helper() -> LocatedError<'static, Boom> {
Located(Boom).into()
}

fn helper_dyn() -> LocatedError<'static, dyn std::error::Error + Send + Sync> {
(Arc::new(Boom) as DynError).into()
}

#[test]
fn located() {
let direct: LocatedError<'static, Boom> = Located(Boom).into();
println!("E9 Located(..).into() written inline : {direct}");
println!("E10 Located(..).into() inside a helper : {}", helper());
println!("E11 DynError .into() inside a helper : {}", helper_dyn());
let closure = || -> LocatedError<'static, Boom> { Located(Boom).into() };
println!("E12 Located(..).into() inside a closure : {}", closure());
}
```

```text
E9 Located(..).into() written inline : boom, packages/configuration/tests/located_error_shapes.rs:19:61
E10 Located(..).into() inside a helper : boom, packages/configuration/tests/located_error_shapes.rs:10:19
E11 DynError .into() inside a helper : boom, packages/configuration/tests/located_error_shapes.rs:14:34
E12 Located(..).into() inside a closure : boom, packages/configuration/tests/located_error_shapes.rs:23:69
```

Reading: `Display` of a `LocatedError` is `{source}, {location}`; E9 reports the call line (19), E10 and
E11 the line inside the helper (10, 14), and E12 the closure line (23).
Loading
Loading