Skip to content

Commit 5894920

Browse files
committed
Better error message on multiple attributes
1 parent 3a887e9 commit 5894920

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ fn extract_cfgs(attrs: Vec<Attribute>) -> (Vec<Attribute>, Vec<Attribute>) {
825825

826826
fn check_attr_whitelist(attrs: &[Attribute]) -> Result<(), TokenStream> {
827827
let whitelist = &["doc", "link_section", "cfg", "allow", "warn", "deny", "forbid", "cold"];
828+
let cortex_m_rt_blacklist = &["entry", "exception", "interrupt", "pre_init"];
828829

829830
'o: for attr in attrs {
830831
for val in whitelist {
@@ -833,6 +834,19 @@ fn check_attr_whitelist(attrs: &[Attribute]) -> Result<(), TokenStream> {
833834
}
834835
}
835836

837+
for val in cortex_m_rt_blacklist {
838+
if eq(&attr, &val) {
839+
return Err(
840+
parse::Error::new(
841+
attr.span(),
842+
"cortex-m-rt does not support multiple attributes on the same function",
843+
)
844+
.to_compile_error()
845+
.into(),
846+
);
847+
}
848+
}
849+
836850
return Err(
837851
parse::Error::new(
838852
attr.span(),

cortex-m-rt/tests/compile-fail/whitelist-double-attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extern crate panic_halt;
77
use cortex_m_rt::{entry, exception};
88

99
#[exception]
10-
#[entry] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt
10+
#[entry] //~ ERROR cortex-m-rt does not support multiple attributes on the same function
1111
fn SVCall() -> ! {
1212
loop {}
1313
}

0 commit comments

Comments
 (0)