Skip to content

Commit 774ad31

Browse files
Check presence of exceptions
1 parent 9a8885f commit 774ad31

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

cortex-m-rt/macros/src/lib.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,20 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
171171
}
172172
}
173173

174-
match exn {
174+
// Emit a reference to the `Exception` variant corresponding to our exception.
175+
// This will fail compilation when the target doesn't have that exception.
176+
let assertion = match exn {
177+
Exception::Other => {
178+
quote! {
179+
const _: () = {
180+
let _ = cortex_m_rt::Exception::#ident;
181+
};
182+
}
183+
}
184+
_ => quote!(),
185+
};
186+
187+
let handler = match exn {
175188
Exception::DefaultHandler => {
176189
let valid_signature = f.sig.constness.is_none()
177190
&& f.vis == Visibility::Inherited
@@ -221,7 +234,6 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
221234

222235
#f
223236
)
224-
.into()
225237
}
226238
Exception::HardFault => {
227239
let valid_signature = f.sig.constness.is_none()
@@ -274,7 +286,6 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
274286

275287
#f
276288
)
277-
.into()
278289
}
279290
Exception::NonMaskableInt | Exception::Other => {
280291
let valid_signature = f.sig.constness.is_none()
@@ -364,9 +375,14 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
364375

365376
#f
366377
)
367-
.into()
368378
}
369-
}
379+
};
380+
381+
quote!(
382+
#assertion
383+
#handler
384+
)
385+
.into()
370386
}
371387

372388
#[proc_macro_attribute]

0 commit comments

Comments
 (0)