diff options
| author | Ulf Lilleengen <[email protected]> | 2025-08-01 06:42:55 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-01 06:42:55 +0000 |
| commit | f3cb0f3c3062cd1b863414186c29b604fab305fa (patch) | |
| tree | be38ef8879e91d3a265f43fcfcf89fd83869a2a4 /embassy-executor/tests/ui/task_safety_attribute.rs | |
| parent | 6409931ef972f6493e7b4d9a93c2cb7bb048d2af (diff) | |
| parent | 54d9a7fed3ab211b1049aae0af0bc49f912c9df4 (diff) | |
Merge pull request #4443 from Brezak/task-unsafe
executor: mark unsafe tasks as unsafe
Diffstat (limited to 'embassy-executor/tests/ui/task_safety_attribute.rs')
| -rw-r--r-- | embassy-executor/tests/ui/task_safety_attribute.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/embassy-executor/tests/ui/task_safety_attribute.rs b/embassy-executor/tests/ui/task_safety_attribute.rs new file mode 100644 index 000000000..ab5a2f99f --- /dev/null +++ b/embassy-executor/tests/ui/task_safety_attribute.rs | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | #![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
| 2 | #![deny(unused_unsafe)] | ||
| 3 | |||
| 4 | use std::mem; | ||
| 5 | |||
| 6 | #[embassy_executor::task] | ||
| 7 | async fn safe() {} | ||
| 8 | |||
| 9 | #[embassy_executor::task] | ||
| 10 | async unsafe fn not_safe() {} | ||
| 11 | |||
| 12 | #[export_name = "__pender"] | ||
| 13 | fn pender(_: *mut ()) { | ||
| 14 | // The test doesn't link if we don't include this. | ||
| 15 | // We never call this anyway. | ||
| 16 | } | ||
| 17 | |||
| 18 | fn main() { | ||
| 19 | let _forget_me = safe(); | ||
| 20 | // SAFETY: not_safe has not safety preconditions | ||
| 21 | let _forget_me2 = unsafe { not_safe() }; | ||
| 22 | |||
| 23 | mem::forget(_forget_me); | ||
| 24 | mem::forget(_forget_me2); | ||
| 25 | } | ||
