#![feature(format_args_capture)] support #445

Closed
opened 2021-01-23 04:52:19 -06:00 by ghost · 1 comment
ghost commented 2021-01-23 04:52:19 -06:00 (Migrated from github.com)

It would be great if this crate supports #![feature(format_args_capture)]. It currently does not (playground):

#![feature(format_args_capture)]

fn main() {
    env_logger::init();
    let x = 0;
    log::error!("{x}");
}

The above program logs {x} without unused-variables warning because log! treats single argument specially and uses __log_format_args! to validate the argument:
github.com/rust-lang/log@1cd39c01fd/src/macros.rs (L35-L36)

I don't understand why log! treats single argument specially. The __private_api_log code path and __private_api_log_lit path should do the same thing (both of them construct fmt::Arguments):
github.com/rust-lang/log@1cd39c01fd/src/lib.rs (L1481)
github.com/rust-lang/log@1cd39c01fd/src/lib.rs (L1462)

If the (redundant?) single argument special treatment is removed, #![feature(format_args_capture)] will be supported. That is not a breaking change because log! already uses __log_format_args! to validate the argument (edit: not totally true → #407).

I'd like to help if this request is accepted.

It would be great if this crate supports [`#![feature(format_args_capture)]`](https://github.com/rust-lang/rust/issues/67984). It currently does not ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=9237562522889e215864f9df9ea42c19)): ```rust #![feature(format_args_capture)] fn main() { env_logger::init(); let x = 0; log::error!("{x}"); } ``` The above program logs `{x}` *without `unused-variables` warning* because `log!` treats single argument specially and uses `__log_format_args!` to validate the argument: https://github.com/rust-lang/log/blob/1cd39c01fd991e30a7c6eb4ae2b89d9d8af268db/src/macros.rs#L35-L36 I don't understand why `log!` treats single argument specially. The `__private_api_log` code path and `__private_api_log_lit` path should do the same thing (both of them construct `fmt::Arguments`): https://github.com/rust-lang/log/blob/1cd39c01fd991e30a7c6eb4ae2b89d9d8af268db/src/lib.rs#L1481 https://github.com/rust-lang/log/blob/1cd39c01fd991e30a7c6eb4ae2b89d9d8af268db/src/lib.rs#L1462 If the (redundant?) single argument special treatment is removed, `#![feature(format_args_capture)]` will be supported. ~~That is not a breaking change because `log!` already uses `__log_format_args!` to validate the argument~~ (edit: not totally true → #407). I'd like to help if this request is accepted.
sfackler commented 2021-01-23 06:38:41 -06:00 (Migrated from github.com)

That special case existed to minimize the amount of code generated, but it's not compatible with format_args_capture as you pointed out. It should just be removed.

That special case existed to minimize the amount of code generated, but it's not compatible with format_args_capture as you pointed out. It should just be removed.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-rust-lang/log#445
No description provided.