commit expected errors

This commit is contained in:
Melvin Wang 2025-06-18 16:16:06 -07:00
parent 051c63fea2
commit 3a43292097
4 changed files with 46 additions and 8 deletions

View File

@ -3,13 +3,9 @@ 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) };
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<u8, _> = LazyLock::new(closure_capturing_non_sync_variable);
check_sync(LazyLock::new(closure_capturing_non_sync_variable));
}
fn check_sync<T: Sync>(_lazy_lock: T) {}

View File

@ -0,0 +1,24 @@
error[E0277]: `*const u8` cannot be shared between threads safely
--> tests/ui/sync_impl/lazy_lock_function.rs:8:16
|
6 | let closure_capturing_non_sync_variable = || unsafe { core::ptr::read(x_ptr) };
| -- within this `{closure@$DIR/tests/ui/sync_impl/lazy_lock_function.rs:6:47: 6:49}`
7 |
8 | check_sync(LazyLock::new(closure_capturing_non_sync_variable));
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const u8` cannot be shared between threads safely
| |
| required by a bound introduced by this call
|
= help: within `{closure@$DIR/tests/ui/sync_impl/lazy_lock_function.rs:6:47: 6:49}`, the trait `Sync` is not implemented for `*const u8`
= note: required because it appears within the type `&*const u8`
note: required because it's used within this closure
--> tests/ui/sync_impl/lazy_lock_function.rs:6:47
|
6 | let closure_capturing_non_sync_variable = || unsafe { core::ptr::read(x_ptr) };
| ^^
= note: required for `embassy_sync::lazy_lock::LazyLock<u8, {closure@$DIR/tests/ui/sync_impl/lazy_lock_function.rs:6:47: 6:49}>` to implement `Sync`
note: required by a bound in `check_sync`
--> tests/ui/sync_impl/lazy_lock_function.rs:11:18
|
11 | fn check_sync<T: Sync>(_lazy_lock: T) {}
| ^^^^ required by this bound in `check_sync`

View File

@ -0,0 +1,9 @@
error[E0277]: `*mut u8` cannot be shared between threads safely
--> tests/ui/sync_impl/lazy_lock_type.rs:4:16
|
4 | static GLOBAL: LazyLock<*mut u8> = LazyLock::new(|| core::ptr::null_mut());
| ^^^^^^^^^^^^^^^^^ `*mut u8` cannot be shared between threads safely
|
= help: the trait `Sync` is not implemented for `*mut u8`
= note: required for `embassy_sync::lazy_lock::LazyLock<*mut u8>` to implement `Sync`
= note: shared static variables must have a type that implements `Sync`

View File

@ -0,0 +1,9 @@
error[E0277]: `*mut u8` cannot be shared between threads safely
--> tests/ui/sync_impl/once_lock.rs:4:16
|
4 | static GLOBAL: OnceLock<*mut u8> = OnceLock::new();
| ^^^^^^^^^^^^^^^^^ `*mut u8` cannot be shared between threads safely
|
= help: the trait `Sync` is not implemented for `*mut u8`
= note: required for `embassy_sync::once_lock::OnceLock<*mut u8>` to implement `Sync`
= note: shared static variables must have a type that implements `Sync`