aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cortex-m-rt/macros/src/lib.rs26
-rw-r--r--cortex-m-rt/tests/compile-fail/exception-v8only.rs16
2 files changed, 37 insertions, 5 deletions
diff --git a/cortex-m-rt/macros/src/lib.rs b/cortex-m-rt/macros/src/lib.rs
index a486558..74041ef 100644
--- a/cortex-m-rt/macros/src/lib.rs
+++ b/cortex-m-rt/macros/src/lib.rs
@@ -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
@@ -221,7 +234,6 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
#f
)
- .into()
}
Exception::HardFault => {
let valid_signature = f.sig.constness.is_none()
@@ -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()
@@ -364,9 +375,14 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
#f
)
- .into()
}
- }
+ };
+
+ quote!(
+ #assertion
+ #handler
+ )
+ .into()
}
#[proc_macro_attribute]
diff --git a/cortex-m-rt/tests/compile-fail/exception-v8only.rs b/cortex-m-rt/tests/compile-fail/exception-v8only.rs
new file mode 100644
index 0000000..d54f706
--- /dev/null
+++ b/cortex-m-rt/tests/compile-fail/exception-v8only.rs
@@ -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`