Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: values being moved with the debug_warn! macro when compiling with not(debug_assertions) #3446

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

WorldSEnder
Copy link

@WorldSEnder WorldSEnder commented Jan 5, 2025

This unifies the code path by using the cfg! macro instead of #[cfg] attribute. The alternative will move arguments passed to the debug_warn! macro only when compiling without debug_assertions. This version will instead always use additional format arguments by reference.

A minimal test code the shows the avoided bug:

let foo = "foo".to_string(); // A value that is not copy
leptos::logging::debug_warn!("Message: {}", foo); // foo is passed as an additional argument
let _ = foo.len(); // A usage after logging

The above will complain about foo being moved in the unpatched code only when compiling with not(debug_assertions), since in that case the macro expands to a tuple of the arguments which counts as a usage and moves foo (into the void, but still).

Further advantage of the patched code is that the usual format_args! checks run with and without debug_assertions enable.

this unifies the code path. The alternative will *move* arguments passed
to the debug_warn! macro only when compiling without debug_assertions.
This version will instead always use additional format arguments by reference.
@WorldSEnder WorldSEnder changed the title Use cfg! macro instead of #[cfg] attribute Fix: values being moved with the debug_warn! macro when compiling with not(debug_assertions) Jan 5, 2025
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