Skip to content

FP redundant_pattern lifetime mismatch #14928

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

Open
matthiaskrgr opened this issue May 30, 2025 · 1 comment
Open

FP redundant_pattern lifetime mismatch #14928

matthiaskrgr opened this issue May 30, 2025 · 1 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

Comments

@matthiaskrgr
Copy link
Member

Summary

.

Lint Name

redundant_pattern

Reproducer

I tried this code:

#![warn(clippy::redundant_pattern)]
fn _f(mut p @ _: &mut i32) {
    let mut number = 111;
    p = &mut number;
    *p = 2;
    println!("{}", *p);
}

pub fn main() {}

I saw this happen:

warning: the `p @ _` pattern can be written as just `p`
 --> src/main.rs:2:7
  |
2 | fn _f(mut p @ _: &mut i32) {
  |       ^^^^^^^^^ help: try: `mut p`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(clippy::redundant_pattern)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^

the suggested code

#![warn(clippy::redundant_pattern)]
fn _f(mut p: &mut i32) {
    let mut number = 111;
    p = &mut number;
    *p = 2;
    println!("{}", *p);
}

pub fn main() {}

does not compile:

warning: value passed to `p` is never read
 --> src/main.rs:2:11
  |
2 | fn _f(mut p: &mut i32) {
  |           ^
  |
  = help: maybe it is overwritten before being read?
  = note: `#[warn(unused_assignments)]` on by default

error[E0597]: `number` does not live long enough
 --> src/main.rs:4:9
  |
2 | fn _f(mut p: &mut i32) {
  |              - let's call the lifetime of this reference `'1`
3 |     let mut number = 111;
  |         ---------- binding `number` declared here
4 |     p = &mut number;
  |     ----^^^^^^^^^^^
  |     |   |
  |     |   borrowed value does not live long enough
  |     assignment requires that `number` is borrowed for `'1`
...
7 | }
  | - `number` dropped here while still borrowed

For more information about this error, try `rustc --explain E0597`.

Version


Additional Labels

No response

@matthiaskrgr matthiaskrgr 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 May 30, 2025
@matthiaskrgr
Copy link
Member Author

rustc 1.89.0-nightly (1bbd62e54 2025-05-29)
binary: rustc
commit-hash: 1bbd62e547ba5cc08ccb44c27def3d33195d2dd5
commit-date: 2025-05-29
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

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

1 participant