diff options
author | 2020-01-07 21:19:09 +0100 | |
---|---|---|
committer | 2020-01-07 21:19:09 +0100 | |
commit | 5fdbab999bc849fd41e376f5f97f03fdf85c7442 (patch) | |
tree | 3f332dd001430c7fcd7ff65a17a640dfb3614c75 | |
parent | 2f5a6487cfd94d6ccde3128c82fa43bddd2d228f (diff) | |
download | cortex-m-5fdbab999bc849fd41e376f5f97f03fdf85c7442.tar.gz cortex-m-5fdbab999bc849fd41e376f5f97f03fdf85c7442.tar.zst cortex-m-5fdbab999bc849fd41e376f5f97f03fdf85c7442.zip |
Updated per comments
-rw-r--r-- | cortex-m-rt/macros/src/lib.rs | 43 | ||||
-rw-r--r-- | cortex-m-rt/tests/compile-fail/whitelist-1.rs (renamed from cortex-m-rt/tests/compile-fail/blacklist-1.rs) | 6 | ||||
-rw-r--r-- | cortex-m-rt/tests/compile-fail/whitelist-2.rs (renamed from cortex-m-rt/tests/compile-fail/blacklist-2.rs) | 6 | ||||
-rw-r--r-- | cortex-m-rt/tests/compile-fail/whitelist-3.rs (renamed from cortex-m-rt/tests/compile-fail/blacklist-3.rs) | 6 | ||||
-rw-r--r-- | cortex-m-rt/tests/compile-fail/whitelist-4.rs (renamed from cortex-m-rt/tests/compile-fail/blacklist-4.rs) | 6 | ||||
-rw-r--r-- | cortex-m-rt/tests/compiletest.rs | 2 |
6 files changed, 43 insertions, 26 deletions
diff --git a/cortex-m-rt/macros/src/lib.rs b/cortex-m-rt/macros/src/lib.rs index be27165..d18cc58 100644 --- a/cortex-m-rt/macros/src/lib.rs +++ b/cortex-m-rt/macros/src/lib.rs @@ -150,7 +150,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { }) .collect::<Vec<_>>(); - if let Some(error) = check_for_blacklisted_attrs(&f.attrs) { + if let Err(error) = check_attr_whitelist(&f.attrs) { return error; } @@ -351,7 +351,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { let tramp_ident = Ident::new(&format!("{}_trampoline", f.sig.ident), Span::call_site()); let ident = &f.sig.ident; - if let Some(error) = check_for_blacklisted_attrs(&f.attrs) { + if let Err(error) = check_attr_whitelist(&f.attrs) { return error; } @@ -412,7 +412,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { let tramp_ident = Ident::new(&format!("{}_trampoline", f.sig.ident), Span::call_site()); let ident = &f.sig.ident; - if let Some(error) = check_for_blacklisted_attrs(&f.attrs) { + if let Err(error) = check_attr_whitelist(&f.attrs) { return error; } @@ -505,7 +505,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { }) .collect::<Vec<_>>(); - if let Some(error) = check_for_blacklisted_attrs(&f.attrs) { + if let Err(error) = check_attr_whitelist(&f.attrs) { return error; } @@ -682,7 +682,7 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream { }) .collect::<Vec<_>>(); - if let Some(error) = check_for_blacklisted_attrs(&f.attrs) { + if let Err(error) = check_attr_whitelist(&f.attrs) { return error; } @@ -830,23 +830,8 @@ fn extract_cfgs(attrs: Vec<Attribute>) -> (Vec<Attribute>, Vec<Attribute>) { (cfgs, not_cfgs) } -fn check_for_blacklisted_attrs(attrs: &[Attribute]) -> Option<TokenStream> { - if let Some(val) = containts_blacklist_attrs(attrs) { - return Some( - parse::Error::new( - val.span(), - "this attribute is not allowed on a function controlled by cortex-m-rt", - ) - .to_compile_error() - .into(), - ); - } - - None -} - -fn containts_blacklist_attrs(attrs: &[Attribute]) -> Option<Attribute> { - let whitelist = &["doc", "link_section"]; +fn check_attr_whitelist(attrs: &[Attribute]) -> Result<(), TokenStream> { + let whitelist = &["doc", "link_section", "cfg", "allow", "warn", "deny", "forbid", "cold"]; 'o: for attr in attrs { for val in whitelist { @@ -855,10 +840,18 @@ fn containts_blacklist_attrs(attrs: &[Attribute]) -> Option<Attribute> { } } - return Some(attr.clone()); - } + return Err( + parse::Error::new( + attr.span(), + "this attribute is not allowed on a function controlled by cortex-m-rt", + ) + .to_compile_error() + .into(), + ); + + }; - None + Ok(()) } /// Returns `true` if `attr.path` matches `name` diff --git a/cortex-m-rt/tests/compile-fail/blacklist-1.rs b/cortex-m-rt/tests/compile-fail/whitelist-1.rs index e76e221..d8a334c 100644 --- a/cortex-m-rt/tests/compile-fail/blacklist-1.rs +++ b/cortex-m-rt/tests/compile-fail/whitelist-1.rs @@ -19,8 +19,14 @@ fn SysTick() {} #[allow(non_camel_case_types)] enum interrupt { USART1, + USART2, } #[inline] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt #[interrupt] fn USART1() {} + +#[cfg(feature = "device")] +#[cfg_attr(feature = "device", inline)] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt +#[interrupt] +fn USART2() {} diff --git a/cortex-m-rt/tests/compile-fail/blacklist-2.rs b/cortex-m-rt/tests/compile-fail/whitelist-2.rs index 34ec760..1550ca0 100644 --- a/cortex-m-rt/tests/compile-fail/blacklist-2.rs +++ b/cortex-m-rt/tests/compile-fail/whitelist-2.rs @@ -19,8 +19,14 @@ fn SysTick() {} #[allow(non_camel_case_types)] enum interrupt { USART1, + USART2, } #[export_name = "not_allowed"] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt #[interrupt] fn USART1() {} + +#[cfg(feature = "device")] +#[cfg_attr(feature = "device", export_name = "not_allowed")] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt +#[interrupt] +fn USART2() {} diff --git a/cortex-m-rt/tests/compile-fail/blacklist-3.rs b/cortex-m-rt/tests/compile-fail/whitelist-3.rs index 8cc3dda..c8e7bb2 100644 --- a/cortex-m-rt/tests/compile-fail/blacklist-3.rs +++ b/cortex-m-rt/tests/compile-fail/whitelist-3.rs @@ -19,8 +19,14 @@ fn SysTick() {} #[allow(non_camel_case_types)] enum interrupt { USART1, + USART2, } #[no_mangle] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt #[interrupt] fn USART1() {} + +#[cfg(feature = "device")] +#[cfg_attr(feature = "device", no_mangle)] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt +#[interrupt] +fn USART2() {} diff --git a/cortex-m-rt/tests/compile-fail/blacklist-4.rs b/cortex-m-rt/tests/compile-fail/whitelist-4.rs index 150e7f9..f0c5ca2 100644 --- a/cortex-m-rt/tests/compile-fail/blacklist-4.rs +++ b/cortex-m-rt/tests/compile-fail/whitelist-4.rs @@ -19,8 +19,14 @@ fn SysTick() {} #[allow(non_camel_case_types)] enum interrupt { USART1, + USART2, } #[must_use] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt #[interrupt] fn USART1() {} + +#[cfg(feature = "device")] +#[cfg_attr(feature = "device", must_use)] //~ ERROR this attribute is not allowed on a function controlled by cortex-m-rt +#[interrupt] +fn USART2() {} diff --git a/cortex-m-rt/tests/compiletest.rs b/cortex-m-rt/tests/compiletest.rs index 6cea3ac..82dda07 100644 --- a/cortex-m-rt/tests/compiletest.rs +++ b/cortex-m-rt/tests/compiletest.rs @@ -9,7 +9,7 @@ fn run_mode(mode: &'static str) { config.src_base = PathBuf::from(format!("tests/{}", mode)); // config.link_deps(); // Populate config.target_rustcflags with dependencies on the path config.target_rustcflags = - Some("-L target/debug -L target/debug/deps -C panic=abort".to_owned()); + Some("-L target/debug -L target/debug/deps -C panic=abort --cfg feature=\"device\"".to_owned()); // config.clean_rmeta(); // If your tests import the parent crate, this helps with E0464 compiletest::run_tests(&config); |