Skip to content

Conversation

Techcable
Copy link
Member

@Techcable Techcable commented Aug 27, 2025

Attempt to fix issue #342

Due to the need to create &'static RecordStatic at compile time, this is much more difficult than adding support in the log crate.

I tried various combination of inline const and const declaration.
In each case, the track_caller::track_caller test failed to respect the #[track_caller] attribute.

It turns out that there is a bizarre interaction that means Location::caller does not respect #[track_caller] in a const-eval context.

See here for a demo: https://gist.github.com/Techcable/a80e3a4c4d928a2038dc45bd6d91f9e4
You can also run this in the playground.

A workaround would be adding a &'static Location to the slog::Record struct, but this would add another pointer to the record and possibly break backwards compatibility.

Bizarre interaction between const-eval, macro span, #[track_caller], and Location::caller.
Tried many different combinations of inline const, const-fn and const declaration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant