Skip to content
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

Fixes shadow_same's false positive for #7915 #7997

Merged
merged 1 commit into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion clippy_lints/src/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,16 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
PatKind::Binding(_, hir_id, ident, _) => (hir_id, ident),
_ => return,
};

if pat.span.desugaring_kind().is_some() {
return;
}

if ident.span.from_expansion() || ident.span.is_dummy() {
return;
}
let HirId { owner, local_id } = id;

let HirId { owner, local_id } = id;
// get (or insert) the list of items for this owner and symbol
let data = self.bindings.last_mut().unwrap();
let items_with_name = data.entry(ident.name).or_default();
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,10 @@ fn question_mark() -> Option<()> {
None
}

pub async fn foo1(_a: i32) {}

pub async fn foo2(_a: i32, _b: i64) {
let _b = _a;
surechen marked this conversation as resolved.
Show resolved Hide resolved
}

fn main() {}
14 changes: 13 additions & 1 deletion tests/ui/shadow.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,17 @@ note: previous binding is here
LL | let _ = |[x]: [u32; 1]| {
| ^

error: aborting due to 20 previous errors
error: `_b` shadows a previous, unrelated binding
--> $DIR/shadow.rs:85:9
|
LL | let _b = _a;
| ^^
|
note: previous binding is here
--> $DIR/shadow.rs:84:28
|
LL | pub async fn foo2(_a: i32, _b: i64) {
| ^^

error: aborting due to 21 previous errors