Skip to content

fp uninlined-format-args + ref-binding-to-reference #10002

Open

Description

@matthiaskrgr

Summary

These lints together break the code

Lint Name

No response

Reproducer

I tried this code:

#![allow(dead_code)]

struct ST3<'a>(&'a i32); // With lifetime parameter

impl<'a> ST3<'a> {

    fn ctor(v: &'a i32) -> Self {
        Self(v)
    }

    fn pattern(self) {
        let Self(ref v) = self;
        println!("{}", v);
    }
}

fn main() {}

I saw this happen:
cargo clippy --fix -- -Wclippy::uninlined-format-args -Wclippy::ref-binding-to-reference

after fixes were automatically applied the compiler reported errors within these files:

  * src/main.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error: argument never used
  --> src/main.rs:13:25
   |
13 |         println!("{v}", &v);
   |                  -----  ^^ argument never used
   |                  |
   |                  formatting specifier missing

error: aborting due to previous error

Original diagnostics will follow.

warning: variables can be used directly in the `format!` string
  --> src/main.rs:13:9
   |
13 |         println!("{}", v);
   |         ^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
   = note: requested on the command line with `-W clippy::uninlined-format-args`
help: change this to
   |
13 -         println!("{}", v);
13 +         println!("{v}");
   |

warning: this pattern creates a reference to a reference
  --> src/main.rs:12:18
   |
12 |         let Self(ref v) = self;
   |                  ^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ref_binding_to_reference
   = note: requested on the command line with `-W clippy::ref-binding-to-reference`
help: try this
   |
12 ~         let Self(v) = self;
13 ~         println!("{}", &v);
   |

Version

rustc 1.67.0-nightly (e0098a5cc 2022-11-29)
binary: rustc
commit-hash: e0098a5cc3a87d857e597af824d0ce1ed1ad85e0
commit-date: 2022-11-29
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4

Additional Labels

No response

Activity

  1. added
    C-bugCategory: Clippy is not doing the correct thing
    I-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied
    I-false-positiveIssue: The lint was triggered on code it shouldn't have
    on Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions