Skip to content

Commit b5eb154

Browse files
committed
Update tests
1 parent 31a33c2 commit b5eb154

4 files changed

Lines changed: 19 additions & 169 deletions

File tree

‎tests/unit/lambda_capture_ref.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// no-compile
12
#include <assert.h>
23
#include <stddef.h>
34
#include <stdint.h>
@@ -36,5 +37,15 @@ int main() {
3637
assert(arr[0] == 0);
3738
assert(arr[3] == 3);
3839

40+
int total = 0;
41+
auto add = [&t = total](int x) { t += x; };
42+
add(2);
43+
add(3);
44+
assert(total == 5);
45+
46+
auto set_y = [&y = s.y](int v) { y = v; };
47+
set_y(9);
48+
assert(s.y == 9);
49+
3950
return 0;
4051
}

‎tests/unit/lambda_move_only_capture.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ struct Owner {
88
Owner(const Owner &) = delete;
99
Owner(Owner &&o) : p(o.p) { o.p = nullptr; }
1010
~Owner() { delete p; }
11+
auto take() {
12+
return [self = std::move(*this)]() { return *self.p; };
13+
}
1114
};
1215

1316
int main() {
@@ -28,5 +31,10 @@ int main() {
2831
consume();
2932
assert(total == 7);
3033

34+
Owner o2(9);
35+
auto t = o2.take();
36+
assert(o2.p == nullptr);
37+
assert(t() == 9);
38+
3139
return 0;
3240
}

‎tests/unit/out/refcount/lambda_capture_ref.rs‎

Lines changed: 0 additions & 91 deletions
This file was deleted.

‎tests/unit/out/unsafe/lambda_capture_ref.rs‎

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)