aboutsummaryrefslogtreecommitdiff
path: root/tests/cfail/local-token.rs
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2017-07-18 20:03:22 -0500
committerGravatar Jorge Aparicio <jorge@japaric.io> 2017-07-18 20:03:22 -0500
commit97a7e38db7eb0643a6334aba30077622d09e5c85 (patch)
treea561e574a8cb36b748c84f69ee679fe0e61f1899 /tests/cfail/local-token.rs
parenta2b0c9e0d077870441ecdea00108c3a3a394fd9b (diff)
downloadrtic-97a7e38db7eb0643a6334aba30077622d09e5c85.tar.gz
rtic-97a7e38db7eb0643a6334aba30077622d09e5c85.tar.zst
rtic-97a7e38db7eb0643a6334aba30077622d09e5c85.zip
tasks / idle have exclusive access to Threshold, but do not own the token
Diffstat (limited to 'tests/cfail/local-token.rs')
-rw-r--r--tests/cfail/local-token.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/cfail/local-token.rs b/tests/cfail/local-token.rs
new file mode 100644
index 00000000..4c98956b
--- /dev/null
+++ b/tests/cfail/local-token.rs
@@ -0,0 +1,44 @@
+#![deny(warnings)]
+#![feature(const_fn)]
+#![feature(proc_macro)]
+
+#[macro_use(task)]
+extern crate cortex_m_rtfm as rtfm;
+extern crate stm32f103xx;
+
+use rtfm::{app, Threshold};
+
+app! {
+ device: stm32f103xx,
+
+ tasks: {
+ EXTI0: {
+ enabled: true,
+ priority: 1,
+ },
+ }
+}
+
+fn init(_p: init::Peripherals) {}
+
+fn idle() -> ! {
+ loop {}
+}
+
+task!(EXTI0, exti0, Old {
+ token: Option<Threshold> = None;
+});
+
+fn exti0(nt: &mut Threshold, old: &mut Old, _r: EXTI0::Resources) {
+ if let Some(ot) = old.token.take() {
+ let _: (Threshold, Threshold) = (*nt, ot);
+ //~^ error cannot move out of borrowed content
+
+ return
+ }
+
+ // ERROR can't store a threshold token in a local variable, otherwise you
+ // would end up with two threshold tokens in a task (see `if let` above)
+ old.token = Some(*nt);
+ //~^ error cannot move out of borrowed content
+}