rust-clippy/tests/ui/shadow.rs
surechen 846c0bef07 Fixes #7915
Fix shadow_same's positive false for async function's params:

Example Code:
```rust
#![deny(clippy::shadow_same)]

pub async fn foo(_a: i32) {
}
```
Output:
```
error: `_a` is shadowed by itself in `_a
```

Hir:
```rust
pub async fn foo(_a: i32)
 ->
     /*impl Trait*/ #[lang = "from_generator"](move |mut _task_context|
                                                   {
                                                       let _a = _a;
                                                       { let _t = { }; _t }
                                                   })
```

Skip checking async function's params.

changelog: Fix shadow_same's positive false for async function's params
2021-11-21 14:28:44 +08:00

88 lines
1.5 KiB
Rust

#![warn(clippy::shadow_same, clippy::shadow_reuse, clippy::shadow_unrelated)]
fn shadow_same() {
let x = 1;
let x = x;
let mut x = &x;
let x = &mut x;
let x = *x;
}
fn shadow_reuse() -> Option<()> {
let x = ([[0]], ());
let x = x.0;
let x = x[0];
let [x] = x;
let x = Some(x);
let x = foo(x);
let x = || x;
let x = Some(1).map(|_| x)?;
let y = 1;
let y = match y {
1 => 2,
_ => 3,
};
None
}
fn shadow_unrelated() {
let x = 1;
let x = 2;
}
fn syntax() {
fn f(x: u32) {
let x = 1;
}
let x = 1;
match Some(1) {
Some(1) => {},
Some(x) => {
let x = 1;
},
_ => {},
}
if let Some(x) = Some(1) {}
while let Some(x) = Some(1) {}
let _ = |[x]: [u32; 1]| {
let x = 1;
};
}
fn negative() {
match Some(1) {
Some(x) if x == 1 => {},
Some(x) => {},
None => {},
}
match [None, Some(1)] {
[Some(x), None] | [None, Some(x)] => {},
_ => {},
}
if let Some(x) = Some(1) {
let y = 1;
} else {
let x = 1;
let y = 1;
}
let x = 1;
#[allow(clippy::shadow_unrelated)]
let x = 1;
}
fn foo<T>(_: T) {}
fn question_mark() -> Option<()> {
let val = 1;
// `?` expands with a `val` binding
None?;
None
}
pub async fn foo1(_a: i32) {}
pub async fn foo2(_a: i32, _b: i64) {
let _b = _a;
}
fn main() {}