Skip to content
This repository has been 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
Show file tree
Hide file tree
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
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub trait Termination {
fn report(self) -> i32;
}

impl Termination for () {
impl Termination for ! {
fn report(self) -> i32 {
0
}
Expand Down
17 changes: 7 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@
#![feature(lang_items)]
#![feature(linkage)]
#![feature(naked_functions)]
#![feature(never_type)]
#![feature(used)]
#![no_std]

Expand All @@ -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;
Expand Down Expand Up @@ -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)]
() => {
Expand All @@ -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")]
Expand Down