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

Differing uninlined_format_args behavior between stable/beta and nightly? #11470

Closed
smoelius opened this issue Sep 8, 2023 · 3 comments · Fixed by #11473
Closed

Differing uninlined_format_args behavior between stable/beta and nightly? #11470

smoelius opened this issue Sep 8, 2023 · 3 comments · Fixed by #11473
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@smoelius
Copy link
Contributor

smoelius commented Sep 8, 2023

Summary

Sorry, this is weird and I don't know the reason for it.

cargo clippy and cargo +beta clippy produce different warnings than cargo +nightly clippy on this code:

#![allow(clippy::all)]
#![warn(clippy::uninlined_format_args)]

fn main() {
    let path = "x";

    let _ = format!("Failed to open `{}`", path);

    let _ = || format!("Failed to open `{}`", path);
}

The difference does't seem to be a commit: if you checkout tag rust-1.72.0 and run it on the above code, you see the nightly behavior.

The only things I've found that make a difference are: being stable/beta or being a uitest.

Re the latter, if you create a uitest and put both of the expected warnings in the stderr file, the test passes.

I've performed the above experiment on two different OSes (Linux and Mac)---same results.

I've also tried debug vs. release. Again, no difference.

I am really at a loss.

What about being stable/beta or being a uitest could make a difference?

Lint Name

uninlined_format_args

Reproducer

I tried this code with cargo +nightly clippy:

#![allow(clippy::all)]
#![warn(clippy::uninlined_format_args)]

fn main() {
    let path = "x";

    let _ = format!("Failed to open `{}`", path);

    let _ = || format!("Failed to open `{}`", path);
}

I expected to see this happen (the same warnings produced by cargo clippy):

warning: variables can be used directly in the `format!` string
 --> src/main.rs:7:13
  |
7 |     let _ = format!("Failed to open `{}`", path);
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
note: the lint level is defined here
 --> src/main.rs:2:9
  |
2 | #![warn(clippy::uninlined_format_args)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: change this to
  |
7 -     let _ = format!("Failed to open `{}`", path);
7 +     let _ = format!("Failed to open `{path}`");
  |

warning: variables can be used directly in the `format!` string
 --> src/main.rs:9:16
  |
9 |     let _ = || format!("Failed to open `{}`", path);
  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
help: change this to
  |
9 -     let _ = || format!("Failed to open `{}`", path);
9 +     let _ = || format!("Failed to open `{path}`");
  |

warning: `a` (bin "a") generated 2 warnings (run `cargo clippy --fix --bin "a"` to apply 2 suggestions)
    Finished dev [unoptimized + debuginfo] target(s) in 0.08s

Instead, this happened (no warning for the format inside the closure)):

warning: variables can be used directly in the `format!` string
 --> src/main.rs:7:13
  |
7 |     let _ = format!("Failed to open `{}`", path);
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
note: the lint level is defined here
 --> src/main.rs:2:9
  |
2 | #![warn(clippy::uninlined_format_args)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: change this to
  |
7 -     let _ = format!("Failed to open `{}`", path);
7 +     let _ = format!("Failed to open `{path}`");
  |

warning: `a` (bin "a") generated 1 warning (run `cargo clippy --fix --bin "a"` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.09s

Version

rustc 1.74.0-nightly (e3abbd499 2023-09-06)
binary: rustc
commit-hash: e3abbd4994f72888f9e5e44dc89a4102e48c2a54
commit-date: 2023-09-06
host: x86_64-apple-darwin
release: 1.74.0-nightly
LLVM version: 17.0.0
@smoelius smoelius added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Sep 8, 2023
@smoelius
Copy link
Contributor Author

smoelius commented Sep 8, 2023

Could someone please try cargo clippy vs. cargo +nightly clippy on the above code, just to confirm I am not crazy?

@Alexendoo
Copy link
Member

It's because -Zincremental-relative-spans is enabled by default on nightly only for now

The ui tests don't hit the issue because they don't use incremental compilation

@smoelius
Copy link
Contributor Author

smoelius commented Sep 8, 2023

@Alexendoo 🙏 I thought I was losing my mind.

mgeisler added a commit to mgeisler/version-sync that referenced this issue Sep 11, 2023
Due to rust-lang/rust-clippy#11470, some
format strings were not inlined in #135. Running Clippy with a stable
compiler fixes the problem.
@bors bors closed this as completed in b788add Sep 12, 2023
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-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants