diff options
| author | Melvin Wang <[email protected]> | 2025-06-18 16:16:06 -0700 |
|---|---|---|
| committer | Melvin Wang <[email protected]> | 2025-06-18 16:16:12 -0700 |
| commit | 3a432920978dc48f0b4c0a8da7c118415a0708fd (patch) | |
| tree | 9db0e9fca33b4be0f18941a7cc21e6c89ebdc1b9 /embassy-sync/tests | |
| parent | 051c63fea2fdb9cc9773c3bd311e6c423f3d1cd2 (diff) | |
commit expected errors
Diffstat (limited to 'embassy-sync/tests')
4 files changed, 46 insertions, 8 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 index c6e6f7e64..35f5587c0 100644 --- a/embassy-sync/tests/ui/sync_impl/lazy_lock_function.rs +++ b/embassy-sync/tests/ui/sync_impl/lazy_lock_function.rs | |||
| @@ -3,13 +3,9 @@ use embassy_sync::lazy_lock::LazyLock; | |||
| 3 | fn main() { | 3 | fn main() { |
| 4 | let x = 128u8; | 4 | let x = 128u8; |
| 5 | let x_ptr: *const u8 = core::ptr::addr_of!(x); | 5 | let x_ptr: *const u8 = core::ptr::addr_of!(x); |
| 6 | let closure_capturing_non_sync_variable = || unsafe { core::ptr::read(x_ptr) }; | ||
| 6 | 7 | ||
| 7 | let closure_capturing_non_sync_variable = || { | 8 | check_sync(LazyLock::new(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 | } | 9 | } |
| 10 | |||
| 11 | fn check_sync<T: Sync>(_lazy_lock: T) {} | ||
diff --git a/embassy-sync/tests/ui/sync_impl/lazy_lock_function.stderr b/embassy-sync/tests/ui/sync_impl/lazy_lock_function.stderr new file mode 100644 index 000000000..daf79ad28 --- /dev/null +++ b/embassy-sync/tests/ui/sync_impl/lazy_lock_function.stderr | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | error[E0277]: `*const u8` cannot be shared between threads safely | ||
| 2 | --> tests/ui/sync_impl/lazy_lock_function.rs:8:16 | ||
| 3 | | | ||
| 4 | 6 | let closure_capturing_non_sync_variable = || unsafe { core::ptr::read(x_ptr) }; | ||
| 5 | | -- within this `{closure@$DIR/tests/ui/sync_impl/lazy_lock_function.rs:6:47: 6:49}` | ||
| 6 | 7 | | ||
| 7 | 8 | check_sync(LazyLock::new(closure_capturing_non_sync_variable)); | ||
| 8 | | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const u8` cannot be shared between threads safely | ||
| 9 | | | | ||
| 10 | | required by a bound introduced by this call | ||
| 11 | | | ||
| 12 | = 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` | ||
| 13 | = note: required because it appears within the type `&*const u8` | ||
| 14 | note: required because it's used within this closure | ||
| 15 | --> tests/ui/sync_impl/lazy_lock_function.rs:6:47 | ||
| 16 | | | ||
| 17 | 6 | let closure_capturing_non_sync_variable = || unsafe { core::ptr::read(x_ptr) }; | ||
| 18 | | ^^ | ||
| 19 | = 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` | ||
| 20 | note: required by a bound in `check_sync` | ||
| 21 | --> tests/ui/sync_impl/lazy_lock_function.rs:11:18 | ||
| 22 | | | ||
| 23 | 11 | fn check_sync<T: Sync>(_lazy_lock: T) {} | ||
| 24 | | ^^^^ required by this bound in `check_sync` | ||
diff --git a/embassy-sync/tests/ui/sync_impl/lazy_lock_type.stderr b/embassy-sync/tests/ui/sync_impl/lazy_lock_type.stderr new file mode 100644 index 000000000..1ccc54c7a --- /dev/null +++ b/embassy-sync/tests/ui/sync_impl/lazy_lock_type.stderr | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | error[E0277]: `*mut u8` cannot be shared between threads safely | ||
| 2 | --> tests/ui/sync_impl/lazy_lock_type.rs:4:16 | ||
| 3 | | | ||
| 4 | 4 | static GLOBAL: LazyLock<*mut u8> = LazyLock::new(|| core::ptr::null_mut()); | ||
| 5 | | ^^^^^^^^^^^^^^^^^ `*mut u8` cannot be shared between threads safely | ||
| 6 | | | ||
| 7 | = help: the trait `Sync` is not implemented for `*mut u8` | ||
| 8 | = note: required for `embassy_sync::lazy_lock::LazyLock<*mut u8>` to implement `Sync` | ||
| 9 | = note: shared static variables must have a type that implements `Sync` | ||
diff --git a/embassy-sync/tests/ui/sync_impl/once_lock.stderr b/embassy-sync/tests/ui/sync_impl/once_lock.stderr new file mode 100644 index 000000000..e2419f844 --- /dev/null +++ b/embassy-sync/tests/ui/sync_impl/once_lock.stderr | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | error[E0277]: `*mut u8` cannot be shared between threads safely | ||
| 2 | --> tests/ui/sync_impl/once_lock.rs:4:16 | ||
| 3 | | | ||
| 4 | 4 | static GLOBAL: OnceLock<*mut u8> = OnceLock::new(); | ||
| 5 | | ^^^^^^^^^^^^^^^^^ `*mut u8` cannot be shared between threads safely | ||
| 6 | | | ||
| 7 | = help: the trait `Sync` is not implemented for `*mut u8` | ||
| 8 | = note: required for `embassy_sync::once_lock::OnceLock<*mut u8>` to implement `Sync` | ||
| 9 | = note: shared static variables must have a type that implements `Sync` | ||
