Skip to content

Commit 3dd900d

Browse files
committed
Updated to not need blacklist
1 parent 6c0464c commit 3dd900d

File tree

5 files changed

+30
-44
lines changed

5 files changed

+30
-44
lines changed

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

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,6 @@ fn check_attr_whitelist(attrs: &[Attribute], caller: WhiteListCaller) -> Result<
844844
"forbid",
845845
"cold",
846846
];
847-
let cortex_m_rt_blacklist = &["entry", "exception", "interrupt", "pre_init"];
848847

849848
'o: for attr in attrs {
850849
for val in whitelist {
@@ -853,35 +852,22 @@ fn check_attr_whitelist(attrs: &[Attribute], caller: WhiteListCaller) -> Result<
853852
}
854853
}
855854

856-
for val in cortex_m_rt_blacklist {
857-
if eq(&attr, &val) {
858-
let err_str = match caller {
859-
WhiteListCaller::Entry => {
860-
&"this attribute is not allowed on a cortex-m-rt entry point"
861-
}
862-
WhiteListCaller::Exception => {
863-
&"this attribute is not allowed on an exception handler"
864-
}
865-
WhiteListCaller::Interrupt => {
866-
&"this attribute is not allowed on an interrupt handler"
867-
}
868-
WhiteListCaller::PreInit => {
869-
&"this attribute is not allowed on an interrupt handler"
870-
}
871-
};
872-
873-
return Err(parse::Error::new(attr.span(), err_str)
874-
.to_compile_error()
875-
.into());
855+
let err_str = match caller {
856+
WhiteListCaller::Entry => "this attribute is not allowed on a cortex-m-rt entry point",
857+
WhiteListCaller::Exception => {
858+
"this attribute is not allowed on an exception handler controlled by cortex-m-rt"
876859
}
877-
}
860+
WhiteListCaller::Interrupt => {
861+
"this attribute is not allowed on an interrupt handler controlled by cortex-m-rt"
862+
}
863+
WhiteListCaller::PreInit => {
864+
"this attribute is not allowed on a pre-init controlled by cortex-m-rt"
865+
}
866+
};
878867

879-
return Err(parse::Error::new(
880-
attr.span(),
881-
"this attribute is not allowed on a function controlled by cortex-m-rt",
882-
)
883-
.to_compile_error()
884-
.into());
868+
return Err(parse::Error::new(attr.span(), &err_str)
869+
.to_compile_error()
870+
.into());
885871
}
886872

887873
Ok(())

cortex-m-rt/tests/compile-fail/whitelist-1.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ extern crate panic_halt;
66

77
use cortex_m_rt::{entry, exception, interrupt};
88

9-
#[inline] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt
9+
#[inline] //~ ERROR this attribute is not allowed on a cortex-m-rt entry point
1010
#[entry]
1111
fn foo() -> ! {
1212
loop {}
1313
}
1414

15-
#[inline] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt
15+
#[inline] //~ ERROR this attribute is not allowed on an exception handler controlled by cortex-m-rt
1616
#[exception]
1717
fn SysTick() {}
1818

@@ -22,11 +22,11 @@ enum interrupt {
2222
USART2,
2323
}
2424

25-
#[inline] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt
25+
#[inline] //~ ERROR this attribute is not allowed on an interrupt handler controlled by cortex-m-rt
2626
#[interrupt]
2727
fn USART1() {}
2828

2929
#[cfg(feature = "device")]
30-
#[cfg_attr(feature = "device", inline)] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt
30+
#[cfg_attr(feature = "device", inline)] //~ ERROR this attribute is not allowed on an interrupt handler controlled by cortex-m-rt
3131
#[interrupt]
3232
fn USART2() {}

cortex-m-rt/tests/compile-fail/whitelist-2.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ extern crate panic_halt;
66

77
use cortex_m_rt::{entry, exception, interrupt};
88

9-
#[export_name = "not_allowed"] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt
9+
#[export_name = "not_allowed"] //~ ERROR this attribute is not allowed on a cortex-m-rt entry point
1010
#[entry]
1111
fn foo() -> ! {
1212
loop {}
1313
}
1414

15-
#[export_name = "not_allowed"] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt
15+
#[export_name = "not_allowed"] //~ ERROR this attribute is not allowed on an exception handler controlled by cortex-m-rt
1616
#[exception]
1717
fn SysTick() {}
1818

@@ -22,11 +22,11 @@ enum interrupt {
2222
USART2,
2323
}
2424

25-
#[export_name = "not_allowed"] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt
25+
#[export_name = "not_allowed"] //~ ERROR this attribute is not allowed on an interrupt handler controlled by cortex-m-rt
2626
#[interrupt]
2727
fn USART1() {}
2828

2929
#[cfg(feature = "device")]
30-
#[cfg_attr(feature = "device", export_name = "not_allowed")] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt
30+
#[cfg_attr(feature = "device", export_name = "not_allowed")] //~ ERROR this attribute is not allowed on an interrupt handler controlled by cortex-m-rt
3131
#[interrupt]
3232
fn USART2() {}

cortex-m-rt/tests/compile-fail/whitelist-3.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ extern crate panic_halt;
66

77
use cortex_m_rt::{entry, exception, interrupt};
88

9-
#[no_mangle] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt
9+
#[no_mangle] //~ ERROR this attribute is not allowed on a cortex-m-rt entry point
1010
#[entry]
1111
fn foo() -> ! {
1212
loop {}
1313
}
1414

15-
#[no_mangle] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt
15+
#[no_mangle] //~ ERROR this attribute is not allowed on an exception handler controlled by cortex-m-rt
1616
#[exception]
1717
fn SysTick() {}
1818

@@ -22,11 +22,11 @@ enum interrupt {
2222
USART2,
2323
}
2424

25-
#[no_mangle] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt
25+
#[no_mangle] //~ ERROR this attribute is not allowed on an interrupt handler controlled by cortex-m-rt
2626
#[interrupt]
2727
fn USART1() {}
2828

2929
#[cfg(feature = "device")]
30-
#[cfg_attr(feature = "device", no_mangle)] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt
30+
#[cfg_attr(feature = "device", no_mangle)] //~ ERROR this attribute is not allowed on an interrupt handler controlled by cortex-m-rt
3131
#[interrupt]
3232
fn USART2() {}

cortex-m-rt/tests/compile-fail/whitelist-4.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ extern crate panic_halt;
66

77
use cortex_m_rt::{entry, exception, interrupt};
88

9-
#[must_use] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt
9+
#[must_use] //~ ERROR this attribute is not allowed on a cortex-m-rt entry point
1010
#[entry]
1111
fn foo() -> ! {
1212
loop {}
1313
}
1414

15-
#[must_use] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt
15+
#[must_use] //~ ERROR this attribute is not allowed on an exception handler controlled by cortex-m-rt
1616
#[exception]
1717
fn SysTick() {}
1818

@@ -22,11 +22,11 @@ enum interrupt {
2222
USART2,
2323
}
2424

25-
#[must_use] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt
25+
#[must_use] //~ ERROR this attribute is not allowed on an interrupt handler controlled by cortex-m-rt
2626
#[interrupt]
2727
fn USART1() {}
2828

2929
#[cfg(feature = "device")]
30-
#[cfg_attr(feature = "device", must_use)] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt
30+
#[cfg_attr(feature = "device", must_use)] //~ ERROR this attribute is not allowed on an interrupt handler controlled by cortex-m-rt
3131
#[interrupt]
3232
fn USART2() {}

0 commit comments

Comments
 (0)