diff options
| author | Melvin Wang <[email protected]> | 2025-06-18 15:37:05 -0700 |
|---|---|---|
| committer | Melvin Wang <[email protected]> | 2025-06-18 15:37:05 -0700 |
| commit | 905aed45f9c15eef9bf9afa5a6b81ae345694581 (patch) | |
| tree | b7ee277375f9ab985a3fc038067959aef4f90e09 /embassy-sync/tests/ui/sync_impl/lazy_lock_function.rs | |
| parent | dda17cc7cb85e3818d43561102b1fc6358d059c5 (diff) | |
add tests illustrating the problem
Diffstat (limited to 'embassy-sync/tests/ui/sync_impl/lazy_lock_function.rs')
| -rw-r--r-- | embassy-sync/tests/ui/sync_impl/lazy_lock_function.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/embassy-sync/tests/ui/sync_impl/lazy_lock_function.rs b/embassy-sync/tests/ui/sync_impl/lazy_lock_function.rs new file mode 100644 index 000000000..c6e6f7e64 --- /dev/null +++ b/embassy-sync/tests/ui/sync_impl/lazy_lock_function.rs | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | use embassy_sync::lazy_lock::LazyLock; | ||
| 2 | |||
| 3 | fn main() { | ||
| 4 | let x = 128u8; | ||
| 5 | let x_ptr: *const u8 = core::ptr::addr_of!(x); | ||
| 6 | |||
| 7 | let closure_capturing_non_sync_variable = || { | ||
| 8 | unsafe { | ||
| 9 | core::ptr::read(x_ptr) | ||
| 10 | } | ||
| 11 | }; | ||
| 12 | |||
| 13 | // This should fail to compile because the closure captures a non-Sync variable: x_ptr. | ||
| 14 | let _lazy_u8: LazyLock<u8, _> = LazyLock::new(closure_capturing_non_sync_variable); | ||
| 15 | } | ||
