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

Allow format_args! as argument to tr! #25

Merged
merged 1 commit into from
Aug 2, 2024

Conversation

rodrigorc
Copy link
Contributor

Hi, again!

The tr! macro does not accept formatting parameters in its placeholders, that is ok, IMO a translation string is better without those. Then the natural thing to do would be to inject them by writing:

tr!("Hello {}", format_args!("{:?}", [1, 2, 3]));

Alas, this fails to compile with a cryptic:

error[E0716]: temporary value dropped while borrowed
   --> tr/src/lib.rs:527:36
    |
174 |             };
    |              - temporary value is freed at the end of this statement
175 |             format!("{}", fa)
    |                           -- borrow later used here

Actually, the doc about format_args! warns about not storing such a value in local variable.

Naturally, I could just use format!(), but format_args! is more efficient.

Fortunately, the fix is quite trivial, as the local variable fa was there only for code style.

@ogoffart ogoffart merged commit 53de644 into woboq:master Aug 2, 2024
3 checks passed
@ogoffart
Copy link
Member

ogoffart commented Aug 2, 2024

Thanks a lot for all your fixes.

Let me know when your queue of fixes is done and I'll make a release on crates.io

@rodrigorc rodrigorc deleted the FormatArgsAsArgument branch August 2, 2024 10:29
@rodrigorc
Copy link
Contributor Author

Let me know when your queue of fixes is done and I'll make a release on crates.io

Just one more. That will be the best and most controversial of all 😉.

BTW, thank you so much for this crate!

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.

2 participants