aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJorge Aparicio <jorge@japaric.io>2019-02-12 11:07:15 +0100
committerJorge Aparicio <jorge@japaric.io>2019-02-12 11:07:15 +0100
commit557a51ede11b39acd37dcadb5bd3e12c4e7e7b28 (patch)
tree580adabe670ed21e865982e883d75cef22328550 /tests
parent91962d21fea9be901125883f2eacbcc426873103 (diff)
forbid early returns in init
Diffstat (limited to 'tests')
-rw-r--r--tests/cfail/early-return-2.rs29
-rw-r--r--tests/cfail/early-return.rs32
2 files changed, 61 insertions, 0 deletions
diff --git a/tests/cfail/early-return-2.rs b/tests/cfail/early-return-2.rs
new file mode 100644
index 0000000..bf867e0
--- /dev/null
+++ b/tests/cfail/early-return-2.rs
@@ -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
+ }
+ }
+};
diff --git a/tests/cfail/early-return.rs b/tests/cfail/early-return.rs
new file mode 100644
index 0000000..fb695aa
--- /dev/null
+++ b/tests/cfail/early-return.rs
@@ -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
+ }
+ }
+};