-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
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
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have