From 0a7f19b547032eea7c923f6c49f5addc14717c00 Mon Sep 17 00:00:00 2001 From: InfRandomness <43730933+InfRandomness@users.noreply.github.com> Date: Sun, 29 May 2022 20:00:11 +0000 Subject: [PATCH] Fix #8748 --- clippy_lints/src/shadow.rs | 10 +++++++--- tests/ui/shadow.rs | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 1ab7f52110c..4f74c1e44c2 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -160,9 +160,13 @@ impl<'tcx> LateLintPass<'tcx> for Shadow { fn is_shadow(cx: &LateContext<'_>, owner: LocalDefId, first: ItemLocalId, second: ItemLocalId) -> bool { let scope_tree = cx.tcx.region_scope_tree(owner.to_def_id()); - let first_scope = scope_tree.var_scope(first).unwrap(); - let second_scope = scope_tree.var_scope(second).unwrap(); - scope_tree.is_subscope_of(second_scope, first_scope) + if let Some(first_scope) = scope_tree.var_scope(first) { + if let Some(second_scope) = scope_tree.var_scope(second) { + return scope_tree.is_subscope_of(second_scope, first_scope); + } + } + + false } fn lint_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, shadowed: HirId, span: Span) { diff --git a/tests/ui/shadow.rs b/tests/ui/shadow.rs index a394ef8f25c..1fa9fc749a9 100644 --- a/tests/ui/shadow.rs +++ b/tests/ui/shadow.rs @@ -88,4 +88,11 @@ pub async fn foo2(_a: i32, _b: i64) { let _b = _a; } +fn ice_8748() { + let _ = [0; { + let x = 1; + if let Some(x) = Some(1) { x } else { 1 } + }]; +} + fn main() {}