]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #8913 - InfRandomness:ICE-#8748, r=giraffate
authorbors <bors@rust-lang.org>
Tue, 31 May 2022 00:17:52 +0000 (00:17 +0000)
committerbors <bors@rust-lang.org>
Tue, 31 May 2022 00:17:52 +0000 (00:17 +0000)
Fix #8748

Thank you for making Clippy better!

changelog: Fix ICE #8748 in shadow.rs

clippy_lints/src/shadow.rs
tests/ui/shadow.rs

index 1ab7f52110ce7c3742aeec202c9ccd4003959e99..4f74c1e44c26d54c9d6cd0a2a9587dfee623820c 100644 (file)
@@ -160,9 +160,13 @@ fn check_body_post(&mut self, cx: &LateContext<'_>, body: &Body<'_>) {
 
 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) {
index a394ef8f25c675b529db3c275eb97308fe835b5b..1fa9fc749a96a1fb1be91ef95e5fbddda482ae30 100644 (file)
@@ -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() {}