From 905aed45f9c15eef9bf9afa5a6b81ae345694581 Mon Sep 17 00:00:00 2001 From: Melvin Wang Date: Wed, 18 Jun 2025 15:37:05 -0700 Subject: add tests illustrating the problem --- embassy-sync/tests/ui/sync_impl/lazy_lock_function.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 embassy-sync/tests/ui/sync_impl/lazy_lock_function.rs (limited to 'embassy-sync/tests/ui/sync_impl/lazy_lock_function.rs') 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 @@ +use embassy_sync::lazy_lock::LazyLock; + +fn main() { + let x = 128u8; + let x_ptr: *const u8 = core::ptr::addr_of!(x); + + let closure_capturing_non_sync_variable = || { + unsafe { + core::ptr::read(x_ptr) + } + }; + + // This should fail to compile because the closure captures a non-Sync variable: x_ptr. + let _lazy_u8: LazyLock = LazyLock::new(closure_capturing_non_sync_variable); +} -- cgit