Support #[track_caller] on EII declarations#158535
Conversation
|
|
This comment has been minimized.
This comment has been minimized.
dc7acb0 to
e1e75ea
Compare
|
Summarizing the Zulip thread for context, there are two directions came up. One requires The discussion landed on propagation, which is what this PR implements. Adding/removing @jdonszelmann whenever you have capacity, could you take a look? |
| // its ABI from the impl's `fn_abi`, so every impl must agree on whether the | ||
| // caller-location argument is present, otherwise it would be silently dropped. | ||
| if tcx | ||
| .body_codegen_attrs(foreign_item) |
There was a problem hiding this comment.
The foreign_item would never be a const or global asm block if this code is reached, right? So you should be able to use codegen_fn_attrs directly.
|
r? bjorn3 |
e1e75ea to
5c33d50
Compare
|
@bors r+ |
Support `#[track_caller]` on EII declarations Tracking issue: rust-lang#125418 Zulip thread: [Zulip](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/Questions.20about.20support.20.60.23.5Btrack_caller.5D.60.20on.20EII.20declaration) `#[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
…uwer Rollup of 17 pull requests Successful merges: - #158510 (Enable `static_position_independent_executables` on all gnu and musl targets) - #158541 (Move `std::io::Write` to `core::io`) - #158899 (Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`) - #155429 (Support `u128`/`i128` c-variadic arguments) - #156370 (Reject linked dylib EII default overrides) - #157153 (allow `Allocator`s to be used as `#[global_allocator]`s) - #158535 (Support `#[track_caller]` on EII declarations) - #158617 (allow mGCA const arguments to fall back to anon consts) - #158645 (Fix splat ICEs and ban it in closures) - #158988 (Redo `TokenStreamIter`) - #158347 (Improve generic parameters handling for #[diagnostic::on_const]) - #158722 (delegation: do not always inherit `ConstArgHasType` predicates) - #158739 (view-types: HIR lowering) - #158883 (tests: fix enum-match.rs to handle LLVM 23) - #158886 (Add documentation for the `no_std` attribute) - #158951 (Merge three `MaxUniverse`s into one) - #158961 (Reapply "LLVM 23: Run AssignGUIDPass in some places")
|
@bors try jobs=aarch64-apple |
|
@bors r- |
This comment has been minimized.
This comment has been minimized.
Support `#[track_caller]` on EII declarations try-job: aarch64-apple
|
This pull request was unapproved. |
|
💔 Test for 69d1e2b failed: CI. Failed job:
|
This comment has been minimized.
This comment has been minimized.
5c33d50 to
f6d756d
Compare
|
On Apple target, using |
|
I don't have an Apple device, so I overlooked this. If anyone has permission, could you please help me rerun a CI test with |
Tracking issue: #125418
Zulip thread: Zulip
#[track_caller]is currently rejected on EII declarations by the catch-all insplit_attrs. This routes it onto the foreign item andderives 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_attralready 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 inadd_function_aliasestakes its ABI from the impl'sfn_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 (seetests/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