about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2021-08-12 11:58:04 +0200
committerMara Bos <m-ou.se@m-ou.se>2021-08-12 12:01:22 +0200
commit99a0477f65101aa6f58b7d8a5845d953da46c91e (patch)
treef4ad01526f5a8da5af0db88d396788c2057ac214 /src
parent945a4b18d949719a1ad737d6d39dda717d62c001 (diff)
downloadrust-99a0477f65101aa6f58b7d8a5845d953da46c91e.tar.gz
rust-99a0477f65101aa6f58b7d8a5845d953da46c91e.zip
Add test for closure migration with a macro body.
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/closures/2229_closure_analysis/migrations/macro.fixed16
-rw-r--r--src/test/ui/closures/2229_closure_analysis/migrations/macro.rs16
-rw-r--r--src/test/ui/closures/2229_closure_analysis/migrations/macro.stderr24
3 files changed, 56 insertions, 0 deletions
diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/macro.fixed b/src/test/ui/closures/2229_closure_analysis/migrations/macro.fixed
new file mode 100644
index 00000000000..3d9797e6579
--- /dev/null
+++ b/src/test/ui/closures/2229_closure_analysis/migrations/macro.fixed
@@ -0,0 +1,16 @@
+// run-rustfix
+
+// See https://github.com/rust-lang/rust/issues/87955
+
+#![deny(rust_2021_incompatible_closure_captures)]
+//~^ NOTE: the lint level is defined here
+
+fn main() {
+    let a = ("hey".to_string(), "123".to_string());
+    let _ = || { let _ = &a; dbg!(a.0) };
+    //~^ ERROR: drop order
+    //~| NOTE: only captures `a.0`
+    //~| NOTE: for more information, see
+    //~| HELP: add a dummy let to cause `a` to be fully captured
+}
+//~^ NOTE: dropped here
diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/macro.rs b/src/test/ui/closures/2229_closure_analysis/migrations/macro.rs
new file mode 100644
index 00000000000..ffceaf0dd22
--- /dev/null
+++ b/src/test/ui/closures/2229_closure_analysis/migrations/macro.rs
@@ -0,0 +1,16 @@
+// run-rustfix
+
+// See https://github.com/rust-lang/rust/issues/87955
+
+#![deny(rust_2021_incompatible_closure_captures)]
+//~^ NOTE: the lint level is defined here
+
+fn main() {
+    let a = ("hey".to_string(), "123".to_string());
+    let _ = || dbg!(a.0);
+    //~^ ERROR: drop order
+    //~| NOTE: only captures `a.0`
+    //~| NOTE: for more information, see
+    //~| HELP: add a dummy let to cause `a` to be fully captured
+}
+//~^ NOTE: dropped here
diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/macro.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/macro.stderr
new file mode 100644
index 00000000000..8ce5844d490
--- /dev/null
+++ b/src/test/ui/closures/2229_closure_analysis/migrations/macro.stderr
@@ -0,0 +1,24 @@
+error: changes to closure capture in Rust 2021 will affect drop order
+  --> $DIR/macro.rs:10:13
+   |
+LL |     let _ = || dbg!(a.0);
+   |             ^^^^^^^^---^
+   |                     |
+   |                     in Rust 2018, closure captures all of `a`, but in Rust 2021, it only captures `a.0`
+...
+LL | }
+   | - in Rust 2018, `a` would be dropped here, but in Rust 2021, only `a.0` would be dropped here alongside the closure
+   |
+note: the lint level is defined here
+  --> $DIR/macro.rs:5:9
+   |
+LL | #![deny(rust_2021_incompatible_closure_captures)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
+help: add a dummy let to cause `a` to be fully captured
+   |
+LL |     let _ = || { let _ = &a; dbg!(a.0) };
+   |                ~~~~~~~~~~~~~~~~~~~~~~~~~
+
+error: aborting due to previous error
+