mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-16 12:55:23 +01:00
forbid early returns in init
This commit is contained in:
parent
91962d21fe
commit
557a51ede1
3 changed files with 307 additions and 1 deletions
29
tests/cfail/early-return-2.rs
Normal file
29
tests/cfail/early-return-2.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate lm3s6965;
|
||||
extern crate panic_halt;
|
||||
extern crate rtfm;
|
||||
|
||||
use rtfm::app;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
static mut UNINITIALIZED: bool = ();
|
||||
|
||||
#[init]
|
||||
fn init() {
|
||||
if false {
|
||||
return; //~ ERROR `init` is *not* allowed to early return
|
||||
}
|
||||
|
||||
UNINITIALIZED = true;
|
||||
}
|
||||
|
||||
#[interrupt(resources = [UNINITIALIZED])]
|
||||
fn UART0() {
|
||||
if resources.UNINITIALIZED {
|
||||
// UB
|
||||
}
|
||||
}
|
||||
};
|
||||
32
tests/cfail/early-return.rs
Normal file
32
tests/cfail/early-return.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate lm3s6965;
|
||||
extern crate panic_halt;
|
||||
extern crate rtfm;
|
||||
|
||||
use rtfm::app;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
static mut UNINITIALIZED: bool = ();
|
||||
|
||||
#[init]
|
||||
fn init() {
|
||||
let x = || {
|
||||
// this is OK
|
||||
return 0;
|
||||
};
|
||||
|
||||
return; //~ ERROR `init` is *not* allowed to early return
|
||||
|
||||
UNINITIALIZED = true;
|
||||
}
|
||||
|
||||
#[interrupt(resources = [UNINITIALIZED])]
|
||||
fn UART0() {
|
||||
if resources.UNINITIALIZED {
|
||||
// UB
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue