Skip to content

Support #[track_caller] on EII declarations#158535

Open
cezarbbb wants to merge 1 commit into
rust-lang:mainfrom
cezarbbb:eii-track-caller
Open

Support #[track_caller] on EII declarations#158535
cezarbbb wants to merge 1 commit into
rust-lang:mainfrom
cezarbbb:eii-track-caller

Conversation

@cezarbbb

@cezarbbb cezarbbb commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Tracking issue: #125418
Zulip thread: Zulip

#[track_caller] is currently rejected on EII declarations by the catch-all in split_attrs. This routes it onto the foreign item and
derives it onto every implementation during codegen.

The foreign item is the symbol callers link against, so it must carry the flag for call sites to append the caller location. It is routed onto the foreign item only, not the default impl — check_attr already rejects #[track_caller] on EII implementations (EiiWithTrackCaller), since the attribute is part of the ABI.

The flag is then derived onto each implementation in codegen_attrs: if the foreign item is #[track_caller], every impl gets the flag too. The shim in add_function_aliases takes its ABI from the impl's fn_abi, so if any impl lacked the flag the caller-location argument would be silently dropped rather than reported as a type error. Deriving it keeps default and explicit impls in sync without requiring users to repeat the attribute.

#[track_caller] on a foreign item is an already-supported path (see tests/ui/rfcs/rfc-2091-track-caller/track-caller-ffi.rs); this just wires it into EII. Statics are unaffected — #[track_caller] isn't a valid target on statics and is rejected as before.

r? @jdonszelmann @bjorn3

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 29, 2026
@rustbot

rustbot commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

jdonszelmann is currently at their maximum review capacity.
They may take a while to respond.

@rust-log-analyzer

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants