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

Check presence of exceptions #308

Merged
merged 2 commits into from
Jan 26, 2021
Merged
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
26 changes: 21 additions & 5 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,20 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
}
}

match exn {
// Emit a reference to the `Exception` variant corresponding to our exception.
// This will fail compilation when the target doesn't have that exception.
let assertion = match exn {
Exception::Other => {
quote! {
const _: () = {
let _ = cortex_m_rt::Exception::#ident;
};
}
}
_ => quote!(),
};

let handler = match exn {
Exception::DefaultHandler => {
let valid_signature = f.sig.constness.is_none()
&& f.vis == Visibility::Inherited
Expand Down Expand Up @@ -221,7 +234,6 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {

#f
)
.into()
}
Exception::HardFault => {
let valid_signature = f.sig.constness.is_none()
Expand Down Expand Up @@ -274,7 +286,6 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {

#f
)
.into()
}
Exception::NonMaskableInt | Exception::Other => {
let valid_signature = f.sig.constness.is_none()
Expand Down Expand Up @@ -364,9 +375,14 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {

#f
)
.into()
}
}
};

quote!(
#assertion
#handler
)
.into()
}

#[proc_macro_attribute]
Expand Down
16 changes: 16 additions & 0 deletions tests/compile-fail/exception-v8only.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![no_main]
#![no_std]

extern crate cortex_m_rt;
extern crate panic_halt;

use cortex_m_rt::{entry, exception};

#[entry]
fn foo() -> ! {
loop {}
}

#[exception]
fn SecureFault() {}
//~^ ERROR no variant or associated item named `SecureFault`