diff options
| author | Henrik Tjäder <henrik@tjaders.com> | 2025-06-08 12:17:58 +0200 |
|---|---|---|
| committer | Emil Fresk <emil.fresk@gmail.com> | 2025-06-08 10:36:54 +0000 |
| commit | ac0579c81f9e8f10321c77432c9ae759e406c371 (patch) | |
| tree | 2e6d4276d9134b755b71dd6b890be2f1251bd7b2 | |
| parent | 8193d5aea66f75c1b40248021760785428a1bf96 (diff) | |
UI: Test for references passed to spawn
Related to and using code from Issue1065
Issue1065: https://github.com/rtic-rs/rtic/issues/1065
| -rw-r--r-- | rtic/ui/task-reference-in-spawn.rs | 29 | ||||
| -rw-r--r-- | rtic/ui/task-reference-in-spawn.stderr | 14 |
2 files changed, 43 insertions, 0 deletions
diff --git a/rtic/ui/task-reference-in-spawn.rs b/rtic/ui/task-reference-in-spawn.rs new file mode 100644 index 0000000..54607af --- /dev/null +++ b/rtic/ui/task-reference-in-spawn.rs @@ -0,0 +1,29 @@ +#![no_main] + +#[rtic::app(device = lm3s6965, dispatchers = [SSI0, QEI0, GPIOA])] +mod app { + #[shared] + struct Shared {} + + #[local] + struct Local {} + + #[init] + fn init(_: init::Context) -> (Shared, Local) { + medium_prio::spawn().unwrap(); + (Shared {}, Local {}) + } + + #[task(priority = 2)] + async fn medium_prio(_: medium_prio::Context) { + let mut will_be_dropped: usize = 41; + will_be_dropped += 1; + + high_prio_print::spawn(&mut will_be_dropped).unwrap(); + } + + #[task(priority = 3)] + async fn high_prio_print(_: high_prio_print::Context, mut_ref: &mut usize) { + *mut_ref += 1000; + } +} diff --git a/rtic/ui/task-reference-in-spawn.stderr b/rtic/ui/task-reference-in-spawn.stderr new file mode 100644 index 0000000..38de78c --- /dev/null +++ b/rtic/ui/task-reference-in-spawn.stderr @@ -0,0 +1,14 @@ +error[E0521]: borrowed data escapes outside of function + --> ui/task-reference-in-spawn.rs:3:1 + | +3 | #[rtic::app(device = lm3s6965, dispatchers = [SSI0, QEI0, GPIOA])] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | `_0` is a reference that is only valid in the function body + | `_0` escapes the function body here + | argument requires that `'1` must outlive `'static` +... +26 | async fn high_prio_print(_: high_prio_print::Context, mut_ref: &mut usize) { + | - let's call the lifetime of this reference `'1` + | + = note: this error originates in the attribute macro `rtic::app` (in Nightly builds, run with -Z macro-backtrace for more info) |
