Skip to content

Commit 846c0be

Browse files
committed
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
1 parent bb58dc8 commit 846c0be

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

clippy_lints/src/shadow.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,16 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
105105
PatKind::Binding(_, hir_id, ident, _) => (hir_id, ident),
106106
_ => return,
107107
};
108+
109+
if pat.span.desugaring_kind().is_some() {
110+
return;
111+
}
112+
108113
if ident.span.from_expansion() || ident.span.is_dummy() {
109114
return;
110115
}
111-
let HirId { owner, local_id } = id;
112116

117+
let HirId { owner, local_id } = id;
113118
// get (or insert) the list of items for this owner and symbol
114119
let data = self.bindings.last_mut().unwrap();
115120
let items_with_name = data.entry(ident.name).or_default();

tests/ui/shadow.rs

+6
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,10 @@ fn question_mark() -> Option<()> {
7979
None
8080
}
8181

82+
pub async fn foo1(_a: i32) {}
83+
84+
pub async fn foo2(_a: i32, _b: i64) {
85+
let _b = _a;
86+
}
87+
8288
fn main() {}

tests/ui/shadow.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -241,5 +241,17 @@ note: previous binding is here
241241
LL | let _ = |[x]: [u32; 1]| {
242242
| ^
243243

244-
error: aborting due to 20 previous errors
244+
error: `_b` shadows a previous, unrelated binding
245+
--> $DIR/shadow.rs:85:9
246+
|
247+
LL | let _b = _a;
248+
| ^^
249+
|
250+
note: previous binding is here
251+
--> $DIR/shadow.rs:84:28
252+
|
253+
LL | pub async fn foo2(_a: i32, _b: i64) {
254+
| ^^
255+
256+
error: aborting due to 21 previous errors
245257

0 commit comments

Comments
 (0)