Skip to content

to_string_in_format_args not caught on nightly without --release #10969

@dan-formlogic

Description

@dan-formlogic

Summary

Nightly clippy does not produce the expected warning for to_string_in_format_args when run locally. However, it does produce the expected error when run in CI in Github Actions or when run with --release.

OS: Ubuntu 20.04.6 LTS in WSL2

Here is the log from github actions installing the nightly rust:


Run actions-rs/toolchain@v1
  with:
    profile: minimal
    toolchain: nightly
    override: true
    components: rustfmt, clippy
    default: false
  env:
    CARGO_TERM_COLOR: always
    SSH_AUTH_SOCK:
    SSH_AGENT_PID:
/home/runner/.cargo/bin/rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/runner/.rustup

stable-x86_64-unknown-linux-gnu (default)
rustc 1.70.0 (90c541806 2023-05-31)
/home/runner/.cargo/bin/rustup -V
rustup 1.26.0 (5af9b9484 2023-04-05)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.70.0 (90c541806 2023-05-31)`
Installed rustup 1.26.0 support profiles
/home/runner/.cargo/bin/rustup -V
rustup 1.26.0 (5af9b9484 2023-04-05)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.70.0 (90c541806 2023-05-31)`
Installed rustup 1.26.0 support components
/home/runner/.cargo/bin/rustup set profile minimal
info: profile set to 'minimal'
/home/runner/.cargo/bin/rustup toolchain install nightly --component rustfmt --component clippy --allow-downgrade
info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
info: latest update on 2023-06-16, rust version 1.72.0-nightly (114fb86ca 2023-06-15)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-std'
info: installing component 'rustc'
info: installing component 'rustfmt'

  nightly-x86_64-unknown-linux-gnu installed - rustc 1.72.0-nightly (114fb86ca 2023-06-15)

info: checking for self-update
warning: tool `rust-analyzer` is already installed, remove it from `/home/runner/.cargo/bin`, then run `rustup update` to have rustup manage this tool.
warning: tool `rustfmt` is already installed, remove it from `/home/runner/.cargo/bin`, then run `rustup update` to have rustup manage this tool.
warning: tool `cargo-fmt` is already installed, remove it from `/home/runner/.cargo/bin`, then run `rustup update` to have rustup manage this tool.
/home/runner/.cargo/bin/rustup override set nightly
info: using existing install for 'nightly-x86_64-unknown-linux-gnu'
info: override toolchain for '/home/runner/work/<redacted>/<redacted>' set to 'nightly-x86_64-unknown-linux-gnu'

  nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.72.0-nightly (114fb86ca 2023-06-15)

Gathering installed versions
  /home/runner/.cargo/bin/rustc -V
  rustc 1.72.0-nightly (114fb86ca 2023-06-15)
  Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
  Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
  /home/runner/.cargo/bin/cargo -V
  cargo 1.72.0-nightly (0c14026aa 2023-06-14)
  Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
  /home/runner/.cargo/bin/rustup -V
  rustup 1.26.0 (5af9b9484 2023-04-05)
  info: This is the version for the rustup toolchain manager, not the rustc compiler.
  info: The currently active `rustc` version is `rustc 1.72.0-nightly (114fb86ca 2023-06-15)`
  Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

Lint Name

to_string_in_format_args

Reproducer

Here is a minimum reproducible example:

use std::fmt::Display;

pub struct MyStruct(String);

impl Display for MyStruct {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "field: {}", self.0)
    }
}

fn main() {
    let something = MyStruct(String::from("Hello, world!"));

    println!("{}", something.to_string());
}

I ran four relevant commands:

  1. cargo clippy (run locally)
  2. cargo +nightly clippy (run locally)
  3. cargo +nightly clippy --release (run locally)
  4. cargo +nightly clippy run in github actions (see above for rust install log from CI)

I expected all three commands to produce the (same) following warning:

warning: `to_string` applied to a type that implements `Display` in `println!` args
 --> src/main.rs:6:29
  |
6 |     println!("{}", something.to_string());
  |                             ^^^^^^^^^^^^ help: remove this
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#to_string_in_format_args
  = note: `#[warn(clippy::to_string_in_format_args)]` on by default

Instead, this happened:

  1. cargo clippy (run locally) -- correctly produced the expected warning.
  2. cargo +nightly clippy (run locally) -- failed to produce the expected warning, instead finishing with no warnings.
  3. cargo +nightly clippy --release (run locally) -- correctly produced the expected warning.
  4. cargo +nightly clippy run in github actions -- DID correctly produce the expected warning -- despite being identical to scenario "2. cargo +nightly clippy (run locally)" as far as I can tell in every way that matters.

Version

**Stable:**
rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: x86_64-unknown-linux-gnu
release: 1.70.0
LLVM version: 16.0.2

**Nightly:**
rustc 1.72.0-nightly (114fb86ca 2023-06-15)
binary: rustc
commit-hash: 114fb86ca08cfa6a99087e0f0bc264d03590dc37
commit-date: 2023-06-15
host: x86_64-unknown-linux-gnu
release: 1.72.0-nightly
LLVM version: 16.0.5

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions