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

literal_string_with_formatting_args false positive on test #13885

Open
tamird opened this issue Dec 27, 2024 · 16 comments · May be fixed by #13953
Open

literal_string_with_formatting_args false positive on test #13885

tamird opened this issue Dec 27, 2024 · 16 comments · May be fixed by #13953
Assignees
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

@tamird
Copy link
Contributor

tamird commented Dec 27, 2024

Summary

See reproducer below. I can't reproduce this in playground because it doesn't run clippy with --all-targets.

Lint Name

literal_string_with_formatting_args

Reproducer

I tried this code:

pub fn parse(_: &str) -> Result<Vec<String>, String> {
    unimplemented!()
}

#[test]
fn test_parse() {
    assert!(parse(
        #[allow(clippy::literal_string_with_formatting_args)]
        "foo {:}"
    )
    .is_err());
}

I saw this happen:

$ cargo +nightly clippy --all-targets
warning: this looks like a formatting argument but it is not part of a formatting macro
 --> src/lib.rs:5:6
  |
5 |     #[test]
  |      ^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#literal_string_with_formatting_args
  = note: `#[warn(clippy::literal_string_with_formatting_args)]` on by default

I expected to see this happen:
No warnings.

Version

rustc 1.85.0-nightly (917bfa784 2024-12-26)
binary: rustc
commit-hash: 917bfa78478cbcc77406e5ea37b24c3eedefacf4
commit-date: 2024-12-26
host: aarch64-apple-darwin
release: 1.85.0-nightly
LLVM version: 19.1.6

Additional Labels

No response

@tamird tamird 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 Dec 27, 2024
@DaniPopes
Copy link
Contributor

DaniPopes commented Dec 27, 2024

Also just encountered this inside of assert!(). Similar/smaller:

pub fn bad() {
    let value = 0;
    assert!(format!("{value}").is_ascii());
}
warning: this looks like a formatting argument but it is not part of a formatting macro
 --> src/lib.rs:2:14
  |
2 |       let value = 0;
  |  ______________^
3 | |     assert!(format!("{value}").is_ascii());
  | |_^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#literal_string_with_formatting_args
  = note: `#[warn(clippy::literal_string_with_formatting_args)]` on by default

playground

It looks like it tries to report the lint on a dummy span + some offset since in my original error it gets reported in lib.rs in some random comment at the top of the file.

@amircodota
Copy link

Got a few more examples

This is an actix-web route

#[route(
    "/forward/{path:.*}",
    method = "GET",
    method = "POST",
    method = "PUT",
    method = "OPTION"
)]
async fn forward(
    request: HttpRequest,
    body: Payload,
    data: Data<HttpState>,
    path: web::Path<String>,
) -> impl Responder {

This is error_chain bail macro

bail!("failed to prepare resumable config object: {e}")

In docs comment

/// Since there's no `lib.rs` or `main.rs` file here in the `tests` directory -

Also appears on some imports with the with word

use crate::common::server_utils::assert_notification_message_with_text;

@profetia
Copy link
Contributor

Might be a FN on from_expansion

@profetia
Copy link
Contributor

@rustbot claim

@samueltardieu
Copy link
Contributor

Ping @GuillaumeGomez

@ilammy
Copy link

ilammy commented Dec 30, 2024

More examples of false positives.

Clippy doesn't like .clippy.toml!

warning: this looks like a formatting argument but it is not part of a formatting macro
 --> [redacted]/.clippy.toml:2:27
  |
2 | too-many-arguments-threshold = 9
  |                           ^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#literal_string_with_formatting_args
  = note: `#[warn(clippy::literal_string_with_formatting_args)]` on by default

I don't know whether it's the attribute or the import that's triggering it:

warning: these look like formatting arguments but are not part of a formatting macro
 --> [redacted]/src/main.rs:1:22
  |
1 | #![allow(clippy::too_long_first_doc_paragraph)]
  |                      ^^^^^^^^
...
9 |         thread::{fresh_run, join_cluster, start_cluster},
  |               ^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#literal_string_with_formatting_args
  = note: `#[warn(clippy::literal_string_with_formatting_args)]` on by default

@profetia
Copy link
Contributor

Just find another way to trigger the FP

// file name: {value}.rs
#![crate_name = "strange_file_name"]
#![allow(unused)]

fn another_bad() {
    let value = 0;
    dbg!("something");
}

fn main() {}

@GuillaumeGomez
Copy link
Member

Wow nice. Gonna take a look in the next days.

@GuillaumeGomez
Copy link
Member

@profetia: I can't trigger the lint with your code.

@GuillaumeGomez
Copy link
Member

I opened #13953.

@profetia
Copy link
Contributor

profetia commented Jan 7, 2025

@GuillaumeGomez You need to put it in a file that is named as {value}.rs.

@ngoldbaum
Copy link

another false positive in PyO3, on feature = "nightly".

https://github.com/PyO3/pyo3/actions/runs/12680326895/job/35341906091?pr=4845#step:7:1086

@larseggert
Copy link

I even see this hit on .clippy.toml, which is quite bizarre:

 --> /Users/lars/Documents/Code/neqo/.clippy.toml:2:68
  |
2 |     { path = "std::slice::from_raw_parts", reason = "see null_safe_slice" }
  |                                                                    ^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#literal_string_with_formatting_args
  = note: `-D clippy::literal-string-with-formatting-args` implied by `-D warnings`
  = help: to override `-D warnings` add `#[allow(clippy::literal_string_with_formatting_args)]`

@GuillaumeGomez
Copy link
Member

Explanation in first comment of #13953.

@amircodota
Copy link

Not sure if the fix for this is in nightly or not. Still on the latest nightly I get the following issues

  1. warning on actix-web routes
#[route(
    "/forward/{path:.*}",
    method = "GET",
    method = "POST",
    method = "PUT",
    method = "OPTION"
)]

This is the warning generated

warning: this looks like a formatting argument but it is not part of a formatting macro
   --> shared/http_endpoints_server/src/server.rs:190:15
    |
190 |     "/forward/{path:.*}",
    |               ^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#literal_string_with_formatting_args
    = note: `#[warn(clippy::literal_string_with_formatting_args)]` on by default
  1. Warning on error_chain::bail macros
warning: this looks like a formatting argument but it is not part of a formatting macro
   --> deep/lunar_local/src/downloader_utils.rs:151:68
    |
151 |                     bail!("failed to initiate HTTPDownload Object: {e}")
    |                                                                    ^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#literal_string_with_formatting_args
    = note: `#[warn(clippy::literal_string_with_formatting_args)]` on by default
  1. warning on imports. Unclear why
use crate::common::template_rendering_utils::{
    call_show_notification_with, create_trigger_manager,
};

This is the warning

warning: this looks like a formatting argument but it is not part of a formatting macro
 --> tabnine/server/tests/template_rendering.rs:5:5
  |
5 |     call_show_notification_with, create_trigger_manager,
  |     ^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#literal_string_with_formatting_args
  = note: `#[warn(clippy::literal_string_with_formatting_args)]` on by default

Same here

use crate::common::server_utils::assert_notification_message_with_text;
warning: this looks like a formatting argument but it is not part of a formatting macro
 --> tabnine/server/tests/template_rendering.rs:3:60
  |
3 | use crate::common::server_utils::assert_notification_message_with_text;
  |                                                            ^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#literal_string_with_formatting_args
  1. Warning in doc comments
/// This file must exist in order to have a package of tests here,
/// Since there's no `lib.rs` or `main.rs` file here in the `tests` directory -
/// This mod serves as a `mod.rs` to include the `advanced_completions_preview_tests` package in.
mod advanced_completions_preview_tests;
mod common;

This is the warning

warning: this looks like a formatting argument but it is not part of a formatting macro
 --> tabnine/server/tests/advanced_completions_tests_mod.rs:2:70
  |
2 |   /// Since there's no `lib.rs` or `main.rs` file here in the `tests` directory -
  |  ______________________________________________________________________^
3 | | /// This mod serves as a `mod.rs` to include the `advanced_completions_preview_tests` package in.
  | |_^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#literal_string_with_formatting_args
  = note: `#[warn(clippy::literal_string_with_formatting_args)]` on by default

@GuillaumeGomez
Copy link
Member

I think some of the warnings might not be covered by #13953. I'll check once merged.

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
9 participants