diff --git a/Cargo.toml b/Cargo.toml index 587633e9..50860340 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ keywords = ["arm", "cortex-m", "runtime", "startup"] license = "MIT OR Apache-2.0" name = "cortex-m-rt" repository = "https://github.com/japaric/cortex-m-rt" -version = "0.3.8" +version = "0.4.0" [dependencies] cortex-m = "0.3.0" diff --git a/src/lang_items.rs b/src/lang_items.rs index 6b15f999..b1027d00 100644 --- a/src/lang_items.rs +++ b/src/lang_items.rs @@ -38,7 +38,7 @@ pub trait Termination { fn report(self) -> i32; } -impl Termination for () { +impl Termination for ! { fn report(self) -> i32 { 0 } diff --git a/src/lib.rs b/src/lib.rs index 9c5e7bf0..226aa3cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -287,6 +287,7 @@ #![feature(lang_items)] #![feature(linkage)] #![feature(naked_functions)] +#![feature(never_type)] #![feature(used)] #![no_std] @@ -307,8 +308,10 @@ use cortex_m::exception::ExceptionFrame; extern "C" { // NOTE `rustc` forces this signature on us. See `src/lang_items.rs` + // NOTE the return type can only be the never type (`!`) because that's the only type that + // implements the `Termination` trait #[cfg(target_arch = "arm")] - fn main(argc: isize, argv: *const *const u8) -> isize; + fn main(argc: isize, argv: *const *const u8) -> !; // Boundaries of the .bss section static mut _ebss: u32; @@ -341,7 +344,7 @@ unsafe extern "C" fn reset_handler() -> ! { () => { // Neither `argc` or `argv` make sense in bare metal context so we // just stub them - main(0, ::core::ptr::null()); + main(0, ::core::ptr::null()) } #[cfg(has_fpu)] () => { @@ -355,21 +358,15 @@ unsafe extern "C" fn reset_handler() -> ! { // be executed *before* enabling the FPU and that would generate an // exception #[inline(never)] - fn main() { + fn main() -> ! { unsafe { - ::main(0, ::core::ptr::null()); + ::main(0, ::core::ptr::null()) } } main() } } - - // If `main` returns, then we go into "reactive" mode and simply attend - // interrupts as they occur. - loop { - asm!("wfi" :::: "volatile"); - } } #[cfg(target_arch = "arm")]