rtic/tests/cfail/critical-section.rs

56 lines
1.1 KiB
Rust
Raw Normal View History

#![deny(unsafe_code)]
#![deny(warnings)]
#![feature(const_fn)]
#![feature(proc_macro)]
2018-05-29 12:23:09 +02:00
#![feature(proc_macro_gen)]
2018-05-14 21:22:50 +02:00
#![no_main]
#![no_std]
extern crate cortex_m_rtfm as rtfm;
2018-05-07 17:46:26 +02:00
extern crate panic_itm;
extern crate stm32f103xx;
2018-05-01 14:01:51 +02:00
use rtfm::{app, Resource};
app! {
device: stm32f103xx,
resources: {
static ON: bool = false;
},
idle: {
resources: [ON],
},
tasks: {
2018-05-01 14:01:51 +02:00
exti0: {
interrupt: EXTI0,
resources: [ON],
},
},
}
2018-05-01 14:01:51 +02:00
fn init(_ctxt: init::Context) -> init::LateResources {
init::LateResources {}
}
fn idle(mut ctxt: idle::Context) -> ! {
2018-05-14 21:22:50 +02:00
let p = &mut ctxt.priority;
2018-05-01 14:01:51 +02:00
let on = ctxt.resources.ON;
2018-05-14 21:22:50 +02:00
let state = rtfm::atomic(p, |p| {
// ERROR borrow can't escape this *global* critical section
2018-05-14 21:22:50 +02:00
on.borrow(p) //~ error cannot infer an appropriate lifetime
});
2018-05-14 21:22:50 +02:00
let state = on.claim(p, |state, _p| {
// ERROR borrow can't escape this critical section
state //~ error cannot infer an appropriate lifetime
});
loop {}
}
2018-05-01 14:01:51 +02:00
fn exti0(_ctxt: exti0::Context) {}