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

#![feature(format_args_capture)] support #445

Closed
ghost opened this issue Jan 23, 2021 · 1 comment · Fixed by #446
Closed

#![feature(format_args_capture)] support #445

ghost opened this issue Jan 23, 2021 · 1 comment · Fixed by #446

Comments

@ghost
Copy link

ghost commented Jan 23, 2021

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:

log/src/macros.rs

Lines 35 to 36 in 1cd39c0

// ensure that $message is a valid format string literal
let _ = __log_format_args!($message);

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):

log/src/lib.rs

Line 1481 in 1cd39c0

.args(format_args!("{}", message))

log/src/lib.rs

Line 1462 in 1cd39c0

.args(args)

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
Copy link
Member

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 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 a pull request may close this issue.

1 participant