about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-10-11 21:39:11 +0000
committerbors <bors@rust-lang.org>2021-10-11 21:39:11 +0000
commit7cc8c44871b6e789d29fc0d42dacad9804c3a41c (patch)
treeea56ac3a075e8aa22a5aeb712e6834ffdf15ed04 /src/test
parent5b210643ebf2485aafdf2494de8cf41941a64e95 (diff)
parent7275cfa47cf3fdbf41c2ad859ac937bffe5923a4 (diff)
downloadrust-7cc8c44871b6e789d29fc0d42dacad9804c3a41c.tar.gz
rust-7cc8c44871b6e789d29fc0d42dacad9804c3a41c.zip
Auto merge of #89648 - nbdd0121:issue-89606, r=nikomatsakis
Ignore type of projections for upvar capturing

Fix #89606

Ignore type of projections for upvar capturing. Originally HashMap is used, and the hash/eq implementation of Place takes the type of projections into account. These types may differ by lifetime which causes #89606 to ICE.

I originally considered erasing regions but `place.ty()` is used when creating upvar tuple type, more than just serving as a key type, so I switched to a linear comparison with custom eq (`compare_place_ignore_ty`) instead.

r? `@wesleywiser`

`@rustbot` label +T-compiler
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/closures/2229_closure_analysis/issue-89606.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/test/ui/closures/2229_closure_analysis/issue-89606.rs b/src/test/ui/closures/2229_closure_analysis/issue-89606.rs
new file mode 100644
index 00000000000..1bb6aa40f06
--- /dev/null
+++ b/src/test/ui/closures/2229_closure_analysis/issue-89606.rs
@@ -0,0 +1,40 @@
+// Regression test for #89606. Used to ICE.
+//
+// check-pass
+// revisions: twenty_eighteen twenty_twentyone
+// [twenty_eighteen]compile-flags: --edition 2018
+// [twenty_twentyone]compile-flags: --edition 2021
+
+struct S<'a>(Option<&'a mut i32>);
+
+fn by_ref(s: &mut S<'_>) {
+    (|| {
+        let S(_o) = s;
+        s.0 = None;
+    })();
+}
+
+fn by_value(s: S<'_>) {
+    (|| {
+        let S(ref _o) = s;
+        let _g = s.0;
+    })();
+}
+
+struct V<'a>((Option<&'a mut i32>,));
+
+fn nested(v: &mut V<'_>) {
+    (|| {
+        let V((_o,)) = v;
+        v.0 = (None, );
+    })();
+}
+
+fn main() {
+    let mut s = S(None);
+    by_ref(&mut s);
+    by_value(s);
+
+    let mut v = V((None, ));
+    nested(&mut v);
+}