diff options
author | 2021-01-26 21:43:33 +0100 | |
---|---|---|
committer | 2021-01-26 21:43:33 +0100 | |
commit | 774ad318fd281dc25eb2863fd521bb7480932a35 (patch) | |
tree | afe9729f038e5d457bdd7dffad5e014c2f489224 | |
parent | 9a8885f4f75d10d18506d13041c80952b9a5a4a2 (diff) | |
download | cortex-m-774ad318fd281dc25eb2863fd521bb7480932a35.tar.gz cortex-m-774ad318fd281dc25eb2863fd521bb7480932a35.tar.zst cortex-m-774ad318fd281dc25eb2863fd521bb7480932a35.zip |
Check presence of exceptions
-rw-r--r-- | cortex-m-rt/macros/src/lib.rs | 26 |
1 files changed, 21 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] |