diff options
author | 2018-10-26 21:01:32 +0000 | |
---|---|---|
committer | 2018-10-26 21:01:32 +0000 | |
commit | f7ab39c983d729d56f5a0d4101e111d5d9fe004f (patch) | |
tree | 9223d3239ab82ca2e0cd3ed1eaa3560967406171 | |
parent | 3d4361409a94774c960e4c95007a8740d558506b (diff) | |
parent | 5baf35a9942621ec38e06ebd98574778e41451bd (diff) | |
download | cortex-m-f7ab39c983d729d56f5a0d4101e111d5d9fe004f.tar.gz cortex-m-f7ab39c983d729d56f5a0d4101e111d5d9fe004f.tar.zst cortex-m-f7ab39c983d729d56f5a0d4101e111d5d9fe004f.zip |
Merge #142
142: attributes: turn panics into compile errors r=therealprof a=japaric
Sample error messages:
```
error: `#[entry]` function must have signature `[unsafe] fn() -> !`
--> examples/error.rs:15:1
|
15 | fn main() {
| ^^
error: aborting due to previous error
```
```
error: This attribute accepts no arguments
--> examples/error.rs:14:1
|
14 | #[entry(hello)]
| ^^^^^^^^^^^^^^^
error: aborting due to previous error
```
```
error: This is not a valid exception name
--> examples/error.rs:20:4
|
20 | fn foo() {}
| ^^^
error: aborting due to previous error
```
Co-authored-by: Jorge Aparicio <jorge@japaric.io>
17 files changed, 229 insertions, 174 deletions
diff --git a/cortex-m-rt/macros/src/lib.rs b/cortex-m-rt/macros/src/lib.rs index 0d29f55..50cea38 100644 --- a/cortex-m-rt/macros/src/lib.rs +++ b/cortex-m-rt/macros/src/lib.rs @@ -14,7 +14,10 @@ use rand::Rng; use rand::SeedableRng; use std::sync::atomic::{AtomicUsize, Ordering}; use std::time::{SystemTime, UNIX_EPOCH}; -use syn::{FnArg, Ident, Item, ItemFn, ItemStatic, ReturnType, Stmt, Type, Visibility}; +use syn::{ + parse, spanned::Spanned, FnArg, Ident, Item, ItemFn, ItemStatic, ReturnType, Stmt, Type, + Visibility, +}; static CALL_COUNT: AtomicUsize = AtomicUsize::new(0); @@ -82,28 +85,35 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { let f = parse_macro_input!(input as ItemFn); // check the function signature - assert!( - f.constness.is_none() - && f.vis == Visibility::Inherited - && f.abi.is_none() - && f.decl.inputs.is_empty() - && f.decl.generics.params.is_empty() - && f.decl.generics.where_clause.is_none() - && f.decl.variadic.is_none() - && match f.decl.output { - ReturnType::Default => false, - ReturnType::Type(_, ref ty) => match **ty { - Type::Never(_) => true, - _ => false, - }, + let valid_signature = f.constness.is_none() + && f.vis == Visibility::Inherited + && f.abi.is_none() + && f.decl.inputs.is_empty() + && f.decl.generics.params.is_empty() + && f.decl.generics.where_clause.is_none() + && f.decl.variadic.is_none() + && match f.decl.output { + ReturnType::Default => false, + ReturnType::Type(_, ref ty) => match **ty { + Type::Never(_) => true, + _ => false, }, - "`#[entry]` function must have signature `[unsafe] fn() -> !`" - ); + }; + + if !valid_signature { + return parse::Error::new( + f.span(), + "`#[entry]` function must have signature `[unsafe] fn() -> !`", + ) + .to_compile_error() + .into(); + } - assert!( - args.to_string() == "", - "`entry` attribute must have no arguments" - ); + if !args.is_empty() { + return parse::Error::new(Span::call_site(), "This attribute accepts no arguments") + .to_compile_error() + .into(); + } // XXX should we blacklist other attributes? let attrs = f.attrs; @@ -128,7 +138,8 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { &mut #ident }; ) - }).collect::<Vec<_>>(); + }) + .collect::<Vec<_>>(); quote!( #[export_name = "main"] @@ -138,7 +149,8 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { #(#stmts)* } - ).into() + ) + .into() } /// Attribute to declare an exception handler @@ -257,11 +269,13 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { let f = parse_macro_input!(input as ItemFn); - assert!( - args.to_string() == "", - "`exception` attribute must have no arguments" - ); + if !args.is_empty() { + return parse::Error::new(Span::call_site(), "This attribute accepts no arguments") + .to_compile_error() + .into(); + } + let fspan = f.span(); let ident = f.ident; enum Exception { @@ -278,7 +292,11 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { // MemoryManagement is not available on Cortex-M0) "NonMaskableInt" | "MemoryManagement" | "BusFault" | "UsageFault" | "SecureFault" | "SVCall" | "DebugMonitor" | "PendSV" | "SysTick" => Exception::Other, - _ => panic!("{} is not a valid exception name", ident_s), + _ => { + return parse::Error::new(ident.span(), "This is not a valid exception name") + .to_compile_error() + .into(); + } }; // XXX should we blacklist other attributes? @@ -290,24 +308,30 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { let hash = random_ident(); match exn { Exception::DefaultHandler => { - assert!( - f.constness.is_none() - && f.vis == Visibility::Inherited - && f.abi.is_none() - && f.decl.inputs.len() == 1 - && f.decl.generics.params.is_empty() - && f.decl.generics.where_clause.is_none() - && f.decl.variadic.is_none() - && match f.decl.output { - ReturnType::Default => true, - ReturnType::Type(_, ref ty) => match **ty { - Type::Tuple(ref tuple) => tuple.elems.is_empty(), - Type::Never(..) => true, - _ => false, - }, + let valid_signature = f.constness.is_none() + && f.vis == Visibility::Inherited + && f.abi.is_none() + && f.decl.inputs.len() == 1 + && f.decl.generics.params.is_empty() + && f.decl.generics.where_clause.is_none() + && f.decl.variadic.is_none() + && match f.decl.output { + ReturnType::Default => true, + ReturnType::Type(_, ref ty) => match **ty { + Type::Tuple(ref tuple) => tuple.elems.is_empty(), + Type::Never(..) => true, + _ => false, }, - "`DefaultHandler` exception must have signature `[unsafe] fn(i16) [-> !]`" - ); + }; + + if !valid_signature { + return parse::Error::new( + fspan, + "`DefaultHandler` must have signature `[unsafe] fn(i16) [-> !]`", + ) + .to_compile_error() + .into(); + } let arg = match f.decl.inputs[0] { FnArg::Captured(ref arg) => arg, @@ -326,35 +350,40 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { #(#stmts)* } - ).into() + ) + .into() } Exception::HardFault => { - assert!( - f.constness.is_none() - && f.vis == Visibility::Inherited - && f.abi.is_none() - && f.decl.inputs.len() == 1 - && match f.decl.inputs[0] { - FnArg::Captured(ref arg) => match arg.ty { - Type::Reference(ref r) => { - r.lifetime.is_none() && r.mutability.is_none() - } - _ => false, - }, + let valid_signature = f.constness.is_none() + && f.vis == Visibility::Inherited + && f.abi.is_none() + && f.decl.inputs.len() == 1 + && match f.decl.inputs[0] { + FnArg::Captured(ref arg) => match arg.ty { + Type::Reference(ref r) => r.lifetime.is_none() && r.mutability.is_none(), _ => false, - } - && f.decl.generics.params.is_empty() - && f.decl.generics.where_clause.is_none() - && f.decl.variadic.is_none() - && match f.decl.output { - ReturnType::Default => false, - ReturnType::Type(_, ref ty) => match **ty { - Type::Never(_) => true, - _ => false, - }, }, - "`HardFault` exception must have signature `[unsafe] fn(&ExceptionFrame) -> !`" - ); + _ => false, + } + && f.decl.generics.params.is_empty() + && f.decl.generics.where_clause.is_none() + && f.decl.variadic.is_none() + && match f.decl.output { + ReturnType::Default => false, + ReturnType::Type(_, ref ty) => match **ty { + Type::Never(_) => true, + _ => false, + }, + }; + + if !valid_signature { + return parse::Error::new( + fspan, + "`HardFault` handler must have signature `[unsafe] fn(&ExceptionFrame) -> !`", + ) + .to_compile_error() + .into(); + } let arg = match f.decl.inputs[0] { FnArg::Captured(ref arg) => arg, @@ -374,28 +403,35 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { #(#stmts)* } - ).into() + ) + .into() } Exception::Other => { - assert!( - f.constness.is_none() - && f.vis == Visibility::Inherited - && f.abi.is_none() - && f.decl.inputs.is_empty() - && f.decl.generics.params.is_empty() - && f.decl.generics.where_clause.is_none() - && f.decl.variadic.is_none() - && match f.decl.output { - ReturnType::Default => true, - ReturnType::Type(_, ref ty) => match **ty { - Type::Tuple(ref tuple) => tuple.elems.is_empty(), - Type::Never(..) => true, - _ => false, - }, + let valid_signature = f.constness.is_none() + && f.vis == Visibility::Inherited + && f.abi.is_none() + && f.decl.inputs.is_empty() + && f.decl.generics.params.is_empty() + && f.decl.generics.where_clause.is_none() + && f.decl.variadic.is_none() + && match f.decl.output { + ReturnType::Default => true, + ReturnType::Type(_, ref ty) => match **ty { + Type::Tuple(ref tuple) => tuple.elems.is_empty(), + Type::Never(..) => true, + _ => false, }, - "`#[exception]` functions other than `DefaultHandler` and `HardFault` must \ - have signature `[unsafe] fn() [-> !]`" - ); + }; + + if !valid_signature { + return parse::Error::new( + fspan, + "`#[exception]` handlers other than `DefaultHandler` and `HardFault` must have \ + signature `[unsafe] fn() [-> !]`", + ) + .to_compile_error() + .into(); + } let (statics, stmts) = extract_static_muts(stmts); @@ -416,7 +452,8 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { &mut #ident }; ) - }).collect::<Vec<_>>(); + }) + .collect::<Vec<_>>(); quote!( #[export_name = #ident_s] @@ -431,7 +468,8 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { #(#stmts)* } - ).into() + ) + .into() } } } @@ -508,11 +546,13 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream { let f: ItemFn = syn::parse(input).expect("`#[interrupt]` must be applied to a function"); - assert!( - args.to_string() == "", - "`interrupt` attribute must have no arguments" - ); + if !args.is_empty() { + return parse::Error::new(Span::call_site(), "This attribute accepts no arguments") + .to_compile_error() + .into(); + } + let fspan = f.span(); let ident = f.ident; let ident_s = ident.to_string(); @@ -522,24 +562,30 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream { let stmts = block.stmts; let unsafety = f.unsafety; - assert!( - f.constness.is_none() - && f.vis == Visibility::Inherited - && f.abi.is_none() - && f.decl.inputs.is_empty() - && f.decl.generics.params.is_empty() - && f.decl.generics.where_clause.is_none() - && f.decl.variadic.is_none() - && match f.decl.output { - ReturnType::Default => true, - ReturnType::Type(_, ref ty) => match **ty { - Type::Tuple(ref tuple) => tuple.elems.is_empty(), - Type::Never(..) => true, - _ => false, - }, + let valid_signature = f.constness.is_none() + && f.vis == Visibility::Inherited + && f.abi.is_none() + && f.decl.inputs.is_empty() + && f.decl.generics.params.is_empty() + && f.decl.generics.where_clause.is_none() + && f.decl.variadic.is_none() + && match f.decl.output { + ReturnType::Default => true, + ReturnType::Type(_, ref ty) => match **ty { + Type::Tuple(ref tuple) => tuple.elems.is_empty(), + Type::Never(..) => true, + _ => false, }, - "`#[interrupt]` functions must have signature `[unsafe] fn() [-> !]`" - ); + }; + + if !valid_signature { + return parse::Error::new( + fspan, + "`#[interrupt]` handlers must have signature `[unsafe] fn() [-> !]`", + ) + .to_compile_error() + .into(); + } let (statics, stmts) = extract_static_muts(stmts); @@ -560,7 +606,8 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream { &mut #ident }; ) - }).collect::<Vec<_>>(); + }) + .collect::<Vec<_>>(); let hash = random_ident(); quote!( @@ -573,7 +620,8 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream { #(#stmts)* } - ).into() + ) + .into() } /// Attribute to mark which function will be called at the beginning of the reset handler. @@ -605,29 +653,36 @@ pub fn pre_init(args: TokenStream, input: TokenStream) -> TokenStream { let f = parse_macro_input!(input as ItemFn); // check the function signature - assert!( - f.constness.is_none() - && f.vis == Visibility::Inherited - && f.unsafety.is_some() - && f.abi.is_none() - && f.decl.inputs.is_empty() - && f.decl.generics.params.is_empty() - && f.decl.generics.where_clause.is_none() - && f.decl.variadic.is_none() - && match f.decl.output { - ReturnType::Default => true, - ReturnType::Type(_, ref ty) => match **ty { - Type::Tuple(ref tuple) => tuple.elems.is_empty(), - _ => false, - }, + let valid_signature = f.constness.is_none() + && f.vis == Visibility::Inherited + && f.unsafety.is_some() + && f.abi.is_none() + && f.decl.inputs.is_empty() + && f.decl.generics.params.is_empty() + && f.decl.generics.where_clause.is_none() + && f.decl.variadic.is_none() + && match f.decl.output { + ReturnType::Default => true, + ReturnType::Type(_, ref ty) => match **ty { + Type::Tuple(ref tuple) => tuple.elems.is_empty(), + _ => false, }, - "`#[pre_init]` function must have signature `unsafe fn()`" - ); + }; + + if !valid_signature { + return parse::Error::new( + f.span(), + "`#[pre_init]` function must have signature `unsafe fn()`", + ) + .to_compile_error() + .into(); + } - assert!( - args.to_string() == "", - "`pre_init` attribute must have no arguments" - ); + if !args.is_empty() { + return parse::Error::new(Span::call_site(), "This attribute accepts no arguments") + .to_compile_error() + .into(); + } // XXX should we blacklist other attributes? let attrs = f.attrs; @@ -638,7 +693,8 @@ pub fn pre_init(args: TokenStream, input: TokenStream) -> TokenStream { #[export_name = "__pre_init"] #(#attrs)* pub unsafe fn #ident() #block - ).into() + ) + .into() } // Creates a random identifier @@ -668,7 +724,8 @@ fn random_ident() -> Ident { } else { ('0' as u8 + rng.gen::<u8>() % 10) as char } - }).collect::<String>(), + }) + .collect::<String>(), Span::call_site(), ) } @@ -681,11 +738,13 @@ fn extract_static_muts(stmts: Vec<Stmt>) -> (Vec<ItemStatic>, Vec<Stmt>) { let mut stmts = vec![]; while let Some(stmt) = istmts.next() { match stmt { - Stmt::Item(Item::Static(var)) => if var.mutability.is_some() { - statics.push(var); - } else { - stmts.push(Stmt::Item(Item::Static(var))); - }, + Stmt::Item(Item::Static(var)) => { + if var.mutability.is_some() { + statics.push(var); + } else { + stmts.push(Stmt::Item(Item::Static(var))); + } + } _ => { stmts.push(stmt); break; diff --git a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs index 72ea0fa..5436115 100644 --- a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs +++ b/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs @@ -11,6 +11,6 @@ fn foo() -> ! { loop {} } -#[exception] //~ ERROR custom attribute panicked -//~^ HELP `DefaultHandler` exception must have signature `[unsafe] fn(i16) [-> !]` +#[exception] fn DefaultHandler(_irqn: i16, undef: u32) {} +//~^ ERROR `DefaultHandler` must have signature `[unsafe] fn(i16) [-> !]` diff --git a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs b/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs index 2e46a6b..1cca10c 100644 --- a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs +++ b/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs @@ -11,8 +11,8 @@ fn foo() -> ! { loop {} } -#[exception] //~ ERROR custom attribute panicked -//~^ HELP `DefaultHandler` exception must have signature `[unsafe] fn(i16) [-> !]` +#[exception] fn DefaultHandler(_irqn: i16) -> u32 { + //~^ ERROR `DefaultHandler` must have signature `[unsafe] fn(i16) [-> !]` 0 } diff --git a/cortex-m-rt/tests/compile-fail/entry-args.rs b/cortex-m-rt/tests/compile-fail/entry-args.rs index b0d293c..5f0b837 100644 --- a/cortex-m-rt/tests/compile-fail/entry-args.rs +++ b/cortex-m-rt/tests/compile-fail/entry-args.rs @@ -6,8 +6,7 @@ extern crate panic_halt; use cortex_m_rt::entry; -#[entry(foo)] //~ ERROR custom attribute panicked -//~^ HELP `entry` attribute must have no arguments +#[entry(foo)] //~ ERROR This attribute accepts no arguments fn foo() -> ! { loop {} } diff --git a/cortex-m-rt/tests/compile-fail/entry-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/entry-bad-signature-1.rs index 5fe9a1a..1ed3649 100644 --- a/cortex-m-rt/tests/compile-fail/entry-bad-signature-1.rs +++ b/cortex-m-rt/tests/compile-fail/entry-bad-signature-1.rs @@ -6,6 +6,6 @@ extern crate panic_halt; use cortex_m_rt::entry; -#[entry] //~ ERROR custom attribute panicked -//~^ HELP `#[entry]` function must have signature `[unsafe] fn() -> !` +#[entry] fn foo() {} +//~^ ERROR `#[entry]` function must have signature `[unsafe] fn() -> !` diff --git a/cortex-m-rt/tests/compile-fail/entry-bad-signature-2.rs b/cortex-m-rt/tests/compile-fail/entry-bad-signature-2.rs index 2b71a57..359444c 100644 --- a/cortex-m-rt/tests/compile-fail/entry-bad-signature-2.rs +++ b/cortex-m-rt/tests/compile-fail/entry-bad-signature-2.rs @@ -6,6 +6,6 @@ extern crate panic_halt; use cortex_m_rt::entry; -#[entry] //~ ERROR custom attribute panicked -//~^ HELP `#[entry]` function must have signature `[unsafe] fn() -> !` +#[entry] fn foo(undef: i32) -> ! {} +//~^ ERROR `#[entry]` function must have signature `[unsafe] fn() -> !` diff --git a/cortex-m-rt/tests/compile-fail/entry-bad-signature-3.rs b/cortex-m-rt/tests/compile-fail/entry-bad-signature-3.rs index 463e5b7..048b0e6 100644 --- a/cortex-m-rt/tests/compile-fail/entry-bad-signature-3.rs +++ b/cortex-m-rt/tests/compile-fail/entry-bad-signature-3.rs @@ -6,8 +6,8 @@ extern crate panic_halt; use cortex_m_rt::entry; -#[entry] //~ ERROR custom attribute panicked -//~^ HELP `#[entry]` function must have signature `[unsafe] fn() -> !` +#[entry] extern "C" fn foo() -> ! { + //~^ ERROR `#[entry]` function must have signature `[unsafe] fn() -> !` loop {} } diff --git a/cortex-m-rt/tests/compile-fail/exception-args.rs b/cortex-m-rt/tests/compile-fail/exception-args.rs index 472a583..518ac03 100644 --- a/cortex-m-rt/tests/compile-fail/exception-args.rs +++ b/cortex-m-rt/tests/compile-fail/exception-args.rs @@ -11,6 +11,5 @@ fn foo() -> ! { loop {} } -#[exception(SysTick)] //~ ERROR custom attribute panicked -//~^ HELP `exception` attribute must have no arguments +#[exception(SysTick)] //~ ERROR This attribute accepts no arguments fn SysTick() {} diff --git a/cortex-m-rt/tests/compile-fail/exception-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/exception-bad-signature-1.rs index e1fbf31..2a046c3 100644 --- a/cortex-m-rt/tests/compile-fail/exception-bad-signature-1.rs +++ b/cortex-m-rt/tests/compile-fail/exception-bad-signature-1.rs @@ -11,6 +11,6 @@ fn foo() -> ! { loop {} } -#[exception] //~ ERROR custom attribute panicked -//~^ HELP `#[exception]` functions other than `DefaultHandler` and `HardFault` must have signature `[unsafe] fn() [-> !]` +#[exception] fn SysTick(undef: u32) {} +//~^ ERROR `#[exception]` handlers other than `DefaultHandler` and `HardFault` must have signature `[unsafe] fn() [-> !]` diff --git a/cortex-m-rt/tests/compile-fail/exception-bad-signature-2.rs b/cortex-m-rt/tests/compile-fail/exception-bad-signature-2.rs index ed46cf6..d2fb210 100644 --- a/cortex-m-rt/tests/compile-fail/exception-bad-signature-2.rs +++ b/cortex-m-rt/tests/compile-fail/exception-bad-signature-2.rs @@ -11,8 +11,8 @@ fn foo() -> ! { loop {} } -#[exception] //~ ERROR custom attribute panicked -//~^ HELP `#[exception]` functions other than `DefaultHandler` and `HardFault` must have signature `[unsafe] fn() [-> !]` +#[exception] fn SysTick() -> u32 { + //~^ ERROR `#[exception]` handlers other than `DefaultHandler` and `HardFault` must have signature `[unsafe] fn() [-> !]` 0 } diff --git a/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs index c2e9c31..d3b4392 100644 --- a/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs +++ b/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs @@ -11,8 +11,8 @@ fn foo() -> ! { loop {} } -#[exception] //~ ERROR custom attribute panicked -//~^ HELP `HardFault` exception must have signature `[unsafe] fn(&ExceptionFrame) -> !` +#[exception] fn HardFault(_ef: &ExceptionFrame, undef: u32) -> ! { + //~^ ERROR `HardFault` handler must have signature `[unsafe] fn(&ExceptionFrame) -> !` loop {} } diff --git a/cortex-m-rt/tests/compile-fail/interrupt-args.rs b/cortex-m-rt/tests/compile-fail/interrupt-args.rs index 36af388..9630ce1 100644 --- a/cortex-m-rt/tests/compile-fail/interrupt-args.rs +++ b/cortex-m-rt/tests/compile-fail/interrupt-args.rs @@ -15,6 +15,5 @@ enum interrupt { USART1, } -#[interrupt(true)] //~ ERROR custom attribute panicked -//~^ HELP `interrupt` attribute must have no arguments +#[interrupt(true)] //~ ERROR This attribute accepts no arguments fn USART1() {} diff --git a/cortex-m-rt/tests/compile-fail/interrupt-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/interrupt-bad-signature-1.rs index 0222413..c7e25b3 100644 --- a/cortex-m-rt/tests/compile-fail/interrupt-bad-signature-1.rs +++ b/cortex-m-rt/tests/compile-fail/interrupt-bad-signature-1.rs @@ -15,6 +15,6 @@ enum interrupt { USART1, } -#[interrupt] //~ ERROR custom attribute panicked -//~^ HELP `#[interrupt]` functions must have signature `[unsafe] fn() [-> !]` +#[interrupt] fn USART1(undef: i32) {} +//~^ ERROR `#[interrupt]` handlers must have signature `[unsafe] fn() [-> !]` diff --git a/cortex-m-rt/tests/compile-fail/interrupt-bad-signature-2.rs b/cortex-m-rt/tests/compile-fail/interrupt-bad-signature-2.rs index 0c9000b..ed5cbd4 100644 --- a/cortex-m-rt/tests/compile-fail/interrupt-bad-signature-2.rs +++ b/cortex-m-rt/tests/compile-fail/interrupt-bad-signature-2.rs @@ -15,8 +15,8 @@ enum interrupt { USART1, } -#[interrupt] //~ ERROR custom attribute panicked -//~^ HELP `#[interrupt]` functions must have signature `[unsafe] fn() [-> !]` +#[interrupt] fn USART1() -> i32 { + //~^ ERROR `#[interrupt]` handlers must have signature `[unsafe] fn() [-> !]` 0 } diff --git a/cortex-m-rt/tests/compile-fail/pre-init-args.rs b/cortex-m-rt/tests/compile-fail/pre-init-args.rs index 94d87bd..9732589 100644 --- a/cortex-m-rt/tests/compile-fail/pre-init-args.rs +++ b/cortex-m-rt/tests/compile-fail/pre-init-args.rs @@ -6,8 +6,7 @@ extern crate panic_halt; use cortex_m_rt::{entry, pre_init}; -#[pre_init(foo)] //~ ERROR custom attribute panicked -//~^ HELP `pre_init` attribute must have no arguments +#[pre_init(foo)] //~ ERROR This attribute accepts no arguments unsafe fn foo() {} #[entry] diff --git a/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-1.rs index 249f477..0c3c476 100644 --- a/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-1.rs +++ b/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-1.rs @@ -6,9 +6,9 @@ extern crate panic_halt; use cortex_m_rt::{entry, pre_init}; -#[pre_init] //~ ERROR custom attribute panicked -//~^ HELP `#[pre_init]` function must have signature `unsafe fn()` +#[pre_init] fn foo() {} +//~^ ERROR `#[pre_init]` function must have signature `unsafe fn()` #[entry] fn bar() -> ! { diff --git a/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-2.rs b/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-2.rs index e942542..f41d032 100644 --- a/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-2.rs +++ b/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-2.rs @@ -6,9 +6,9 @@ extern crate panic_halt; use cortex_m_rt::{entry, pre_init}; -#[pre_init] //~ ERROR custom attribute panicked -//~^ HELP `#[pre_init]` function must have signature `unsafe fn()` +#[pre_init] unsafe fn foo(undef: i32) {} +//~^ ERROR `#[pre_init]` function must have signature `unsafe fn()` #[entry] fn bar() -> ! { |