about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2025-01-25 08:03:35 +0100
committerGitHub <noreply@github.com>2025-01-25 08:03:35 +0100
commiteb3e1c9ee1f55dff0ba7a99e995814d73adefedc (patch)
tree03eb80b4bd9c0d9167660cce285c4ae765efffa5
parent5c821ae4e84e7eae91fe588267dd2610fed5c18c (diff)
parent6c7e8fefa30688f2a750f738bb78da517c4ffc00 (diff)
downloadrust-eb3e1c9ee1f55dff0ba7a99e995814d73adefedc.tar.gz
rust-eb3e1c9ee1f55dff0ba7a99e995814d73adefedc.zip
Rollup merge of #135985 - Zalathar:whats-upvar, r=lqd
Rename test to `unresolvable-upvar-issue-87987.rs` and add some notes

Extracted from #135756. I had to figure out what this test was trying to test, so I might as well write it down for future reference.
-rw-r--r--src/tools/tidy/src/issues.txt1
-rw-r--r--tests/ui/closures/2229_closure_analysis/issue-87987.rs27
-rw-r--r--tests/ui/closures/2229_closure_analysis/issue-87987.stderr14
-rw-r--r--tests/ui/closures/2229_closure_analysis/unresolvable-upvar-issue-87987.rs46
4 files changed, 46 insertions, 42 deletions
diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt
index 0e5a7458b68..5865664fc89 100644
--- a/src/tools/tidy/src/issues.txt
+++ b/src/tools/tidy/src/issues.txt
@@ -409,7 +409,6 @@ ui/closure_context/issue-26046-fn-once.rs
 ui/closure_context/issue-42065.rs
 ui/closures/2229_closure_analysis/issue-118144.rs
 ui/closures/2229_closure_analysis/issue-87378.rs
-ui/closures/2229_closure_analysis/issue-87987.rs
 ui/closures/2229_closure_analysis/issue-88118-2.rs
 ui/closures/2229_closure_analysis/issue-88476.rs
 ui/closures/2229_closure_analysis/issue-89606.rs
diff --git a/tests/ui/closures/2229_closure_analysis/issue-87987.rs b/tests/ui/closures/2229_closure_analysis/issue-87987.rs
deleted file mode 100644
index f79a8f1b571..00000000000
--- a/tests/ui/closures/2229_closure_analysis/issue-87987.rs
+++ /dev/null
@@ -1,27 +0,0 @@
-//@ run-pass
-//@ edition:2021
-
-struct Props {
-    field_1: u32, //~ WARNING: fields `field_1` and `field_2` are never read
-    field_2: u32,
-}
-
-fn main() {
-    // Test 1
-    let props_2 = Props { field_1: 1, field_2: 1 };
-
-    let _ = || {
-        let _: Props = props_2;
-    };
-
-    // Test 2
-    let mut arr = [1, 3, 4, 5];
-
-    let mref = &mut arr;
-
-    let _c = || match arr {
-        [_, _, _, _] => println!("A"),
-    };
-
-    println!("{:#?}", mref);
-}
diff --git a/tests/ui/closures/2229_closure_analysis/issue-87987.stderr b/tests/ui/closures/2229_closure_analysis/issue-87987.stderr
deleted file mode 100644
index 5696a010c3f..00000000000
--- a/tests/ui/closures/2229_closure_analysis/issue-87987.stderr
+++ /dev/null
@@ -1,14 +0,0 @@
-warning: fields `field_1` and `field_2` are never read
-  --> $DIR/issue-87987.rs:5:5
-   |
-LL | struct Props {
-   |        ----- fields in this struct
-LL |     field_1: u32,
-   |     ^^^^^^^
-LL |     field_2: u32,
-   |     ^^^^^^^
-   |
-   = note: `#[warn(dead_code)]` on by default
-
-warning: 1 warning emitted
-
diff --git a/tests/ui/closures/2229_closure_analysis/unresolvable-upvar-issue-87987.rs b/tests/ui/closures/2229_closure_analysis/unresolvable-upvar-issue-87987.rs
new file mode 100644
index 00000000000..c501e034c97
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/unresolvable-upvar-issue-87987.rs
@@ -0,0 +1,46 @@
+//! When a closure syntactically captures a place, but doesn't actually capture
+//! it, make sure MIR building doesn't ICE when handling that place.
+//!
+//! Under the Rust 2021 disjoint capture rules, this sort of non-capture can
+//! occur when a place is only inspected by infallible non-binding patterns.
+
+// FIXME(#135985): On its own, this test should probably just be check-pass.
+// But there are few/no other tests that use non-binding array patterns and
+// invoke the later parts of the compiler, so building/running has some value.
+
+//@ run-pass
+//@ edition:2021
+
+#[expect(dead_code)]
+struct Props {
+    field_1: u32,
+    field_2: u32,
+}
+
+fn main() {
+    // Test 1
+    let props_2 = Props { field_1: 1, field_2: 1 };
+
+    let _ = || {
+        let _: Props = props_2;
+    };
+
+    // Test 2
+    let mut arr = [1, 3, 4, 5];
+
+    let mref = &mut arr;
+
+    // These array patterns don't need to inspect the array, so the array
+    // isn't captured.
+    let _c = || match arr {
+        [_, _, _, _] => println!("C"),
+    };
+    let _d = || match arr {
+        [_, .., _] => println!("D"),
+    };
+    let _e = || match arr {
+        [_, ..] => println!("E"),
+    };
+
+    println!("{:#?}", mref);
+}