Skip to content

Commit 3278be6

Browse files
Merge #308
308: Check presence of exceptions r=adamgreig a=jonas-schievink Closes rust-embedded/cortex-m-rt#214 Co-authored-by: Jonas Schievink <[email protected]>
2 parents 9a8885f + 8ebb044 commit 3278be6

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-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]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
extern crate cortex_m_rt;
5+
extern crate panic_halt;
6+
7+
use cortex_m_rt::{entry, exception};
8+
9+
#[entry]
10+
fn foo() -> ! {
11+
loop {}
12+
}
13+
14+
#[exception]
15+
fn SecureFault() {}
16+
//~^ ERROR no variant or associated item named `SecureFault`

0 commit comments

Comments
 (0)