Skip to content

Commit f7ab39c

Browse files
bors[bot]japaric
andcommitted
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 <[email protected]>
2 parents 3d43614 + 5baf35a commit f7ab39c

17 files changed

+229
-174
lines changed

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

+201-142
Large diffs are not rendered by default.

cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ fn foo() -> ! {
1111
loop {}
1212
}
1313

14-
#[exception] //~ ERROR custom attribute panicked
15-
//~^ HELP `DefaultHandler` exception must have signature `[unsafe] fn(i16) [-> !]`
14+
#[exception]
1615
fn DefaultHandler(_irqn: i16, undef: u32) {}
16+
//~^ ERROR `DefaultHandler` must have signature `[unsafe] fn(i16) [-> !]`

cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ fn foo() -> ! {
1111
loop {}
1212
}
1313

14-
#[exception] //~ ERROR custom attribute panicked
15-
//~^ HELP `DefaultHandler` exception must have signature `[unsafe] fn(i16) [-> !]`
14+
#[exception]
1615
fn DefaultHandler(_irqn: i16) -> u32 {
16+
//~^ ERROR `DefaultHandler` must have signature `[unsafe] fn(i16) [-> !]`
1717
0
1818
}

cortex-m-rt/tests/compile-fail/entry-args.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ extern crate panic_halt;
66

77
use cortex_m_rt::entry;
88

9-
#[entry(foo)] //~ ERROR custom attribute panicked
10-
//~^ HELP `entry` attribute must have no arguments
9+
#[entry(foo)] //~ ERROR This attribute accepts no arguments
1110
fn foo() -> ! {
1211
loop {}
1312
}

cortex-m-rt/tests/compile-fail/entry-bad-signature-1.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ extern crate panic_halt;
66

77
use cortex_m_rt::entry;
88

9-
#[entry] //~ ERROR custom attribute panicked
10-
//~^ HELP `#[entry]` function must have signature `[unsafe] fn() -> !`
9+
#[entry]
1110
fn foo() {}
11+
//~^ ERROR `#[entry]` function must have signature `[unsafe] fn() -> !`

cortex-m-rt/tests/compile-fail/entry-bad-signature-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ extern crate panic_halt;
66

77
use cortex_m_rt::entry;
88

9-
#[entry] //~ ERROR custom attribute panicked
10-
//~^ HELP `#[entry]` function must have signature `[unsafe] fn() -> !`
9+
#[entry]
1110
fn foo(undef: i32) -> ! {}
11+
//~^ ERROR `#[entry]` function must have signature `[unsafe] fn() -> !`

cortex-m-rt/tests/compile-fail/entry-bad-signature-3.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ extern crate panic_halt;
66

77
use cortex_m_rt::entry;
88

9-
#[entry] //~ ERROR custom attribute panicked
10-
//~^ HELP `#[entry]` function must have signature `[unsafe] fn() -> !`
9+
#[entry]
1110
extern "C" fn foo() -> ! {
11+
//~^ ERROR `#[entry]` function must have signature `[unsafe] fn() -> !`
1212
loop {}
1313
}

cortex-m-rt/tests/compile-fail/exception-args.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ fn foo() -> ! {
1111
loop {}
1212
}
1313

14-
#[exception(SysTick)] //~ ERROR custom attribute panicked
15-
//~^ HELP `exception` attribute must have no arguments
14+
#[exception(SysTick)] //~ ERROR This attribute accepts no arguments
1615
fn SysTick() {}

cortex-m-rt/tests/compile-fail/exception-bad-signature-1.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ fn foo() -> ! {
1111
loop {}
1212
}
1313

14-
#[exception] //~ ERROR custom attribute panicked
15-
//~^ HELP `#[exception]` functions other than `DefaultHandler` and `HardFault` must have signature `[unsafe] fn() [-> !]`
14+
#[exception]
1615
fn SysTick(undef: u32) {}
16+
//~^ ERROR `#[exception]` handlers other than `DefaultHandler` and `HardFault` must have signature `[unsafe] fn() [-> !]`

cortex-m-rt/tests/compile-fail/exception-bad-signature-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ fn foo() -> ! {
1111
loop {}
1212
}
1313

14-
#[exception] //~ ERROR custom attribute panicked
15-
//~^ HELP `#[exception]` functions other than `DefaultHandler` and `HardFault` must have signature `[unsafe] fn() [-> !]`
14+
#[exception]
1615
fn SysTick() -> u32 {
16+
//~^ ERROR `#[exception]` handlers other than `DefaultHandler` and `HardFault` must have signature `[unsafe] fn() [-> !]`
1717
0
1818
}

cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ fn foo() -> ! {
1111
loop {}
1212
}
1313

14-
#[exception] //~ ERROR custom attribute panicked
15-
//~^ HELP `HardFault` exception must have signature `[unsafe] fn(&ExceptionFrame) -> !`
14+
#[exception]
1615
fn HardFault(_ef: &ExceptionFrame, undef: u32) -> ! {
16+
//~^ ERROR `HardFault` handler must have signature `[unsafe] fn(&ExceptionFrame) -> !`
1717
loop {}
1818
}

cortex-m-rt/tests/compile-fail/interrupt-args.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ enum interrupt {
1515
USART1,
1616
}
1717

18-
#[interrupt(true)] //~ ERROR custom attribute panicked
19-
//~^ HELP `interrupt` attribute must have no arguments
18+
#[interrupt(true)] //~ ERROR This attribute accepts no arguments
2019
fn USART1() {}

cortex-m-rt/tests/compile-fail/interrupt-bad-signature-1.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ enum interrupt {
1515
USART1,
1616
}
1717

18-
#[interrupt] //~ ERROR custom attribute panicked
19-
//~^ HELP `#[interrupt]` functions must have signature `[unsafe] fn() [-> !]`
18+
#[interrupt]
2019
fn USART1(undef: i32) {}
20+
//~^ ERROR `#[interrupt]` handlers must have signature `[unsafe] fn() [-> !]`

cortex-m-rt/tests/compile-fail/interrupt-bad-signature-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ enum interrupt {
1515
USART1,
1616
}
1717

18-
#[interrupt] //~ ERROR custom attribute panicked
19-
//~^ HELP `#[interrupt]` functions must have signature `[unsafe] fn() [-> !]`
18+
#[interrupt]
2019
fn USART1() -> i32 {
20+
//~^ ERROR `#[interrupt]` handlers must have signature `[unsafe] fn() [-> !]`
2121
0
2222
}

cortex-m-rt/tests/compile-fail/pre-init-args.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ extern crate panic_halt;
66

77
use cortex_m_rt::{entry, pre_init};
88

9-
#[pre_init(foo)] //~ ERROR custom attribute panicked
10-
//~^ HELP `pre_init` attribute must have no arguments
9+
#[pre_init(foo)] //~ ERROR This attribute accepts no arguments
1110
unsafe fn foo() {}
1211

1312
#[entry]

cortex-m-rt/tests/compile-fail/pre-init-bad-signature-1.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ extern crate panic_halt;
66

77
use cortex_m_rt::{entry, pre_init};
88

9-
#[pre_init] //~ ERROR custom attribute panicked
10-
//~^ HELP `#[pre_init]` function must have signature `unsafe fn()`
9+
#[pre_init]
1110
fn foo() {}
11+
//~^ ERROR `#[pre_init]` function must have signature `unsafe fn()`
1212

1313
#[entry]
1414
fn bar() -> ! {

cortex-m-rt/tests/compile-fail/pre-init-bad-signature-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ extern crate panic_halt;
66

77
use cortex_m_rt::{entry, pre_init};
88

9-
#[pre_init] //~ ERROR custom attribute panicked
10-
//~^ HELP `#[pre_init]` function must have signature `unsafe fn()`
9+
#[pre_init]
1110
unsafe fn foo(undef: i32) {}
11+
//~^ ERROR `#[pre_init]` function must have signature `unsafe fn()`
1212

1313
#[entry]
1414
fn bar() -> ! {

0 commit comments

Comments
 (0)