summaryrefslogtreecommitdiffstats
path: root/tests/ui/closures/2229_closure_analysis/migrations/no_migrations.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/closures/2229_closure_analysis/migrations/no_migrations.rs')
-rw-r--r--tests/ui/closures/2229_closure_analysis/migrations/no_migrations.rs81
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/ui/closures/2229_closure_analysis/migrations/no_migrations.rs b/tests/ui/closures/2229_closure_analysis/migrations/no_migrations.rs
new file mode 100644
index 000000000..8b75e226a
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/migrations/no_migrations.rs
@@ -0,0 +1,81 @@
+// run-pass
+
+// Set of test cases that don't need migrations
+
+#![deny(rust_2021_incompatible_closure_captures)]
+
+// Copy types as copied by the closure instead of being moved into the closure
+// Therefore their drop order isn't tied to the closure and won't be requiring any
+// migrations.
+fn test1_only_copy_types() {
+ let t = (0i32, 0i32);
+
+ let c = || {
+ let _t = t.0;
+ };
+
+ c();
+}
+
+// Same as test1 but using a move closure
+fn test2_only_copy_types_move_closure() {
+ let t = (0i32, 0i32);
+
+ let c = move || {
+ println!("{}", t.0);
+ };
+
+ c();
+}
+
+// Don't need to migrate if captured by ref
+fn test3_only_copy_types_move_closure() {
+ let t = (String::new(), String::new());
+
+ let c = || {
+ println!("{}", t.0);
+ };
+
+ c();
+}
+
+// Test migration analysis in case of Insignificant Drop + Non Drop aggregates.
+// Note in this test the closure captures a non Drop type and therefore the variable
+// is only captured by ref.
+fn test4_insignificant_drop_non_drop_aggregate() {
+ let t = (String::new(), 0i32);
+
+ let c = || {
+ let _t = t.1;
+ };
+
+ c();
+}
+
+struct Foo(i32);
+impl Drop for Foo {
+ fn drop(&mut self) {
+ println!("{:?} dropped", self.0);
+ }
+}
+
+// Test migration analysis in case of Significant Drop + Non Drop aggregates.
+// Note in this test the closure captures a non Drop type and therefore the variable
+// is only captured by ref.
+fn test5_significant_drop_non_drop_aggregate() {
+ let t = (Foo(0), 0i32);
+
+ let c = || {
+ let _t = t.1;
+ };
+
+ c();
+}
+
+fn main() {
+ test1_only_copy_types();
+ test2_only_copy_types_move_closure();
+ test3_only_copy_types_move_closure();
+ test4_insignificant_drop_non_drop_aggregate();
+ test5_significant_drop_non_drop_aggregate();
+}