Skip to content

uninlined-format-args suggests broken code for assert! macros in 2018 edition #10234

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

Open
inikulin opened this issue Jan 26, 2023 · 5 comments
Open
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@inikulin
Copy link

Summary

uninlined-format-args, which is now enforced by default, complains about format literals passed to the assert! macros, but inlined format args don't work with them in 2018 edition.

Reproducer

I tried this code:

fn main() {
    let hey = 42;
    
    assert!(false, "foo is {hey}");
}

I expected to see this happen: this to work as suggested by clippy

Instead, this happened: compilation warning + foo is {hey} being a panic message instead of foo is 42

Version

rustc 1.67.0 (fc594f156 2023-01-24)
binary: rustc
commit-hash: fc594f15669680fa70d255faec3ca3fb507c3405
commit-date: 2023-01-24
host: x86_64-apple-darwin
release: 1.67.0
LLVM version: 15.0.6

Additional Labels

No response

@inikulin inikulin added the C-bug Category: Clippy is not doing the correct thing label Jan 26, 2023
@taiki-e
Copy link
Member

taiki-e commented Jan 27, 2023

This was fixed in rust-lang/rust@e5010c9 (#10055), but that patch is only included in 1.68 and later, not 1.67.

@djc
Copy link
Contributor

djc commented Jan 27, 2023

In https://github.com/tokio-rs/tls/actions/runs/4021612870/jobs/6910637824 I noticed this for a plain format!() call, does the fix from #10055 also apply to this?

@taiki-e
Copy link
Member

taiki-e commented Jan 27, 2023

@djc I don't think it's a false positive. format_args_capture for format! is supported in all editions since Rust 1.58.0.
(This issue is about a bug that suggests using format_args_capture for panic!/assert!/debug_assert! that is not supported in the 2015/2018 edition.)

@djc
Copy link
Contributor

djc commented Jan 27, 2023

That's fair, thanks!

Zaggy1024 added a commit to Zaggy1024/mp4parse-rust that referenced this issue Jan 30, 2023
One error had to be ignored for now due to the false positive in rust-lang/rust-clippy#10234, which is fixed in 1.68.
kinetiknz pushed a commit to mozilla/mp4parse-rust that referenced this issue Jan 31, 2023
One error had to be ignored for now due to the false positive in rust-lang/rust-clippy#10234, which is fixed in 1.68.
@nyurik
Copy link
Contributor

nyurik commented May 4, 2023

Should this be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

No branches or pull requests

4 participants