Inconsistency in formated output with respect to functions in standard lib. #407
Labels
No labels
bug
duplicate
easy
enhancement
help wanted
invalid
question
rfc
structured-logging
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-rust-lang/log#407
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Using log 0.4.11, the following code:
produces this output:
This is due to
github.com/rust-lang/log@f06a18d010/src/macros.rs (L36)checking that the message is correct when there are no arguments but ignoring the result and logging the original message.Standard rust macros (
format!,write!,println!, ...) callstd::format_args!which already handles both cases:github.com/rust-lang/rust@ac48e62db8/library/alloc/src/macros.rs (L105-L110)github.com/rust-lang/rust@4b0882cfaa/library/core/src/macros/mod.rs (L792-L795)If you think it is desirable to have a behavior that is analog to rust macros, I can try doing the change.
The same code with
4.0.8gives the expected result.We started special-casing the no-args case to minimize codegen, but it seems like that's not quite the correct behavior: https://github.com/rust-lang/log/blob/master/src/lib.rs#L1388-L1403.
That special case will need to go away anyway to support https://github.com/rust-lang/rfcs/blob/master/text/2795-format-args-implicit-identifiers.md.
There's a new API on Arguments that we should be able to use to recover this optimization: https://github.com/rust-lang/rust/pull/74056
Fixed by #446. If Arguments.as_str stabilizes, we can use that to add the optimization back.