Skip to content
This repository was archived by the owner on Jan 24, 2022. It is now read-only.

[RFC] enforce main: fn() -> ! #50

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion src/lang_items.rs
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ pub trait Termination {
fn report(self) -> i32;
}

impl Termination for () {
impl Termination for ! {
fn report(self) -> i32 {
0
}
17 changes: 7 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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")]