Skip to content

Commit 588e198

Browse files
committed
Auto merge of #8913 - InfRandomness:ICE-#8748, r=giraffate
Fix #8748 Thank you for making Clippy better! changelog: Fix ICE #8748 in shadow.rs
2 parents d9f4978 + 0a7f19b commit 588e198

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

clippy_lints/src/shadow.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,13 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
160160

161161
fn is_shadow(cx: &LateContext<'_>, owner: LocalDefId, first: ItemLocalId, second: ItemLocalId) -> bool {
162162
let scope_tree = cx.tcx.region_scope_tree(owner.to_def_id());
163-
let first_scope = scope_tree.var_scope(first).unwrap();
164-
let second_scope = scope_tree.var_scope(second).unwrap();
165-
scope_tree.is_subscope_of(second_scope, first_scope)
163+
if let Some(first_scope) = scope_tree.var_scope(first) {
164+
if let Some(second_scope) = scope_tree.var_scope(second) {
165+
return scope_tree.is_subscope_of(second_scope, first_scope);
166+
}
167+
}
168+
169+
false
166170
}
167171

168172
fn lint_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, shadowed: HirId, span: Span) {

tests/ui/shadow.rs

+7
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,11 @@ pub async fn foo2(_a: i32, _b: i64) {
8888
let _b = _a;
8989
}
9090

91+
fn ice_8748() {
92+
let _ = [0; {
93+
let x = 1;
94+
if let Some(x) = Some(1) { x } else { 1 }
95+
}];
96+
}
97+
9198
fn main() {}

0 commit comments

Comments
 (0)