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

Commit

Permalink
Merge #308
Browse files Browse the repository at this point in the history
308: Check presence of exceptions r=adamgreig a=jonas-schievink

Closes #214

Co-authored-by: Jonas Schievink <[email protected]>
  • Loading branch information
bors[bot] and jonas-schievink authored Jan 26, 2021
2 parents 4aee094 + 30b2ab1 commit 835d9fa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
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`

0 comments on commit 835d9fa

Please sign in to comment.