Skip to content

Edition <2021 uninlined_format_args fix causes non_fmt_panics #10236

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

Closed
alexheretic opened this issue Jan 27, 2023 · 3 comments
Closed

Edition <2021 uninlined_format_args fix causes non_fmt_panics #10236

alexheretic opened this issue Jan 27, 2023 · 3 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@alexheretic
Copy link
Member

Summary

uninlined_format_args can be false positive for older edition, e.g. 2018, where some macros do not support such formatting.

Lint Name

uninlined_format_args

Reproducer

I tried this code:

// Cargo.toml edition = "2018"
let v = vec![1];
assert!(v.is_empty(), "v non-empty: {:?}", v);

I saw this happen:

warning: variables can be used directly in the `format!` string
  --> src/main.rs:11:5
   |
11 |     assert!(v.is_empty(), "v non-empty: {:?}", v);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
   = note: `#[warn(clippy::uninlined_format_args)]` on by default
help: change this to
   |
11 -     assert!(v.is_empty(), "v non-empty: {:?}", v);
11 +     assert!(v.is_empty(), "v non-empty: {v:?}");
   |

I expected to see this happen:

No such warning unless on at least edition 2021.

If the fix is applied to older editions it'll result in the rustc warning

warning: panic message contains an unused formatting placeholder
 --> src/main.rs:9:37
  |
9 | assert!(v.is_empty(), "v non-empty: {v:?}");
  |                                     ^^^^^
  |
  = note: this message is not used as a format string when given without arguments, but will be in Rust 2021

And indeed it will not work outputting thread 'main' panicked at 'v non-empty: {v:?}' (instead of thread 'main' panicked at 'v non-empty: [1]')

Version

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

Additional Labels

No response

@alexheretic alexheretic added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jan 27, 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.

@taiki-e
Copy link
Member

taiki-e commented Jan 27, 2023

(Also this issue is duplicate of #10234)

@alexheretic
Copy link
Member Author

thanks

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 I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

2 participants