aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cortex-m-rt/ci/script.sh6
-rw-r--r--cortex-m-rt/examples/divergent-default-handler.rs (renamed from cortex-m-rt/tests/compile-fail/default-handler-bad-signature-3.rs)5
-rw-r--r--cortex-m-rt/examples/divergent-exception.rs (renamed from cortex-m-rt/tests/compile-fail/exception-bad-signature-3.rs)4
-rw-r--r--cortex-m-rt/examples/unsafe-default-handler.rs (renamed from cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs)4
-rw-r--r--cortex-m-rt/examples/unsafe-entry.rs13
-rw-r--r--cortex-m-rt/examples/unsafe-exception.rs (renamed from cortex-m-rt/tests/compile-fail/exception-bad-signature-2.rs)4
-rw-r--r--cortex-m-rt/examples/unsafe-hard-fault.rs (renamed from cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-2.rs)4
-rw-r--r--cortex-m-rt/macros/src/lib.rs32
-rw-r--r--cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs2
-rw-r--r--cortex-m-rt/tests/compile-fail/entry-bad-signature-1.rs2
-rw-r--r--cortex-m-rt/tests/compile-fail/entry-bad-signature-2.rs2
-rw-r--r--cortex-m-rt/tests/compile-fail/entry-bad-signature-3.rs4
-rw-r--r--cortex-m-rt/tests/compile-fail/entry-bad-signature-4.rs13
-rw-r--r--cortex-m-rt/tests/compile-fail/exception-bad-signature-1.rs2
-rw-r--r--cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs2
15 files changed, 52 insertions, 47 deletions
diff --git a/cortex-m-rt/ci/script.sh b/cortex-m-rt/ci/script.sh
index ce1aec8..cecb975 100644
--- a/cortex-m-rt/ci/script.sh
+++ b/cortex-m-rt/ci/script.sh
@@ -13,12 +13,18 @@ main() {
local examples=(
alignment
+ divergent-default-handler
+ divergent-exception
entry-static
main
minimal
override-exception
pre_init
state
+ unsafe-default-handler
+ unsafe-hard-fault
+ unsafe-entry
+ unsafe-exception
)
local fail_examples=(
data_overflow
diff --git a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-3.rs b/cortex-m-rt/examples/divergent-default-handler.rs
index c827b6a..cbb8bb1 100644
--- a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-3.rs
+++ b/cortex-m-rt/examples/divergent-default-handler.rs
@@ -1,3 +1,5 @@
+#![deny(unsafe_code)]
+#![deny(warnings)]
#![no_main]
#![no_std]
@@ -11,8 +13,7 @@ fn foo() -> ! {
loop {}
}
-#[exception] //~ ERROR custom attribute panicked
-//~^ HELP `DefaultHandler` exception must have signature `fn(i16)`
+#[exception]
fn DefaultHandler(_irqn: i16) -> ! {
loop {}
}
diff --git a/cortex-m-rt/tests/compile-fail/exception-bad-signature-3.rs b/cortex-m-rt/examples/divergent-exception.rs
index 546ef90..9998884 100644
--- a/cortex-m-rt/tests/compile-fail/exception-bad-signature-3.rs
+++ b/cortex-m-rt/examples/divergent-exception.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
#![no_main]
#![no_std]
@@ -11,8 +12,7 @@ fn foo() -> ! {
loop {}
}
-#[exception] //~ ERROR custom attribute panicked
-//~^ HELP `#[exception]` functions other than `DefaultHandler` and `HardFault` must have signature `fn()`
+#[exception]
fn SysTick() -> ! {
loop {}
}
diff --git a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs b/cortex-m-rt/examples/unsafe-default-handler.rs
index ec74993..48bd31e 100644
--- a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs
+++ b/cortex-m-rt/examples/unsafe-default-handler.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
#![no_main]
#![no_std]
@@ -11,6 +12,5 @@ fn foo() -> ! {
loop {}
}
-#[exception] //~ ERROR custom attribute panicked
-//~^ HELP `DefaultHandler` exception must have signature `fn(i16)`
+#[exception]
unsafe fn DefaultHandler(_irqn: i16) {}
diff --git a/cortex-m-rt/examples/unsafe-entry.rs b/cortex-m-rt/examples/unsafe-entry.rs
new file mode 100644
index 0000000..feb6f44
--- /dev/null
+++ b/cortex-m-rt/examples/unsafe-entry.rs
@@ -0,0 +1,13 @@
+#![deny(warnings)]
+#![no_main]
+#![no_std]
+
+extern crate cortex_m_rt;
+extern crate panic_semihosting;
+
+use cortex_m_rt::entry;
+
+#[entry]
+unsafe fn foo() -> ! {
+ loop {}
+}
diff --git a/cortex-m-rt/tests/compile-fail/exception-bad-signature-2.rs b/cortex-m-rt/examples/unsafe-exception.rs
index 8b1011d..d67f06f 100644
--- a/cortex-m-rt/tests/compile-fail/exception-bad-signature-2.rs
+++ b/cortex-m-rt/examples/unsafe-exception.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
#![no_main]
#![no_std]
@@ -11,6 +12,5 @@ fn foo() -> ! {
loop {}
}
-#[exception] //~ ERROR custom attribute panicked
-//~^ HELP `#[exception]` functions other than `DefaultHandler` and `HardFault` must have signature `fn()`
+#[exception]
unsafe fn SysTick() {}
diff --git a/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-2.rs b/cortex-m-rt/examples/unsafe-hard-fault.rs
index add6943..b091d47 100644
--- a/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-2.rs
+++ b/cortex-m-rt/examples/unsafe-hard-fault.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
#![no_main]
#![no_std]
@@ -11,8 +12,7 @@ fn foo() -> ! {
loop {}
}
-#[exception] //~ ERROR custom attribute panicked
-//~^ HELP `HardFault` exception must have signature `fn(&ExceptionFrame) -> !`
+#[exception]
unsafe fn HardFault(_ef: &ExceptionFrame) -> ! {
loop {}
}
diff --git a/cortex-m-rt/macros/src/lib.rs b/cortex-m-rt/macros/src/lib.rs
index da21954..2619a44 100644
--- a/cortex-m-rt/macros/src/lib.rs
+++ b/cortex-m-rt/macros/src/lib.rs
@@ -22,7 +22,7 @@ use proc_macro::TokenStream;
/// the case of the `thumbv7em-none-eabihf` target the FPU will also be enabled before the function
/// is called.
///
-/// The type of the specified function must be `fn() -> !` (never ending function)
+/// The type of the specified function must be `[unsafe] fn() -> !` (never ending function)
///
/// # Properties
///
@@ -76,7 +76,6 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
assert!(
f.constness.is_none()
&& f.vis == Visibility::Inherited
- && f.unsafety.is_none()
&& f.abi.is_none()
&& f.decl.inputs.is_empty()
&& f.decl.generics.params.is_empty()
@@ -89,7 +88,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
_ => false,
},
},
- "`#[entry]` function must have signature `fn() -> !`"
+ "`#[entry]` function must have signature `[unsafe] fn() -> !`"
);
assert!(
@@ -173,19 +172,19 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
/// # Usage
///
/// `#[exception] fn HardFault(..` sets the hard fault handler. The handler must have signature
-/// `fn(&ExceptionFrame) -> !`. This handler is not allowed to return as that can cause undefined
-/// behavior.
+/// `[unsafe] fn(&ExceptionFrame) -> !`. This handler is not allowed to return as that can cause
+/// undefined behavior.
///
/// `#[exception] fn DefaultHandler(..` sets the *default* handler. All exceptions which have not
/// been assigned a handler will be serviced by this handler. This handler must have signature
-/// `fn(irqn: i16)`. `irqn` is the IRQ number (See CMSIS); `irqn` will be a negative number when the
-/// handler is servicing a core exception; `irqn` will be a positive number when the handler is
-/// servicing a device specific exception (interrupt).
+/// `[unsafe] fn(irqn: i16) [-> !]`. `irqn` is the IRQ number (See CMSIS); `irqn` will be a negative
+/// number when the handler is servicing a core exception; `irqn` will be a positive number when the
+/// handler is servicing a device specific exception (interrupt).
///
/// `#[exception] fn Name(..` overrides the default handler for the exception with the given `Name`.
-/// When overriding these other exception it's possible to add state to them by declaring `static
-/// mut` variables at the beginning of the body of the function. These variables will be safe to
-/// access from the function body.
+/// These handlers must have signature `[unsafe] fn() [-> !]`. When overriding these other exception
+/// it's possible to add state to them by declaring `static mut` variables at the beginning of the
+/// body of the function. These variables will be safe to access from the function body.
///
/// # Properties
///
@@ -284,7 +283,6 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
assert!(
f.constness.is_none()
&& f.vis == Visibility::Inherited
- && f.unsafety.is_none()
&& f.abi.is_none()
&& f.decl.inputs.len() == 1
&& f.decl.generics.params.is_empty()
@@ -294,10 +292,11 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
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 `fn(i16)`"
+ "`DefaultHandler` exception must have signature `[unsafe] fn(i16) [-> !]`"
);
let arg = match f.decl.inputs[0] {
@@ -323,7 +322,6 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
assert!(
f.constness.is_none()
&& f.vis == Visibility::Inherited
- && f.unsafety.is_none()
&& f.abi.is_none()
&& f.decl.inputs.len() == 1
&& match f.decl.inputs[0] {
@@ -345,7 +343,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
_ => false,
},
},
- "`HardFault` exception must have signature `fn(&ExceptionFrame) -> !`"
+ "`HardFault` exception must have signature `[unsafe] fn(&ExceptionFrame) -> !`"
);
let arg = match f.decl.inputs[0] {
@@ -372,7 +370,6 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
assert!(
f.constness.is_none()
&& f.vis == Visibility::Inherited
- && f.unsafety.is_none()
&& f.abi.is_none()
&& f.decl.inputs.is_empty()
&& f.decl.generics.params.is_empty()
@@ -382,11 +379,12 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
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 `fn()`"
+ have signature `[unsafe] fn() [-> !]`"
);
let (statics, stmts) = extract_static_muts(stmts);
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 a2c16c1..037e9c8 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
@@ -12,5 +12,5 @@ fn foo() -> ! {
}
#[exception] //~ ERROR custom attribute panicked
-//~^ HELP `DefaultHandler` exception must have signature `fn(i16)`
+//~^ HELP `DefaultHandler` exception must have signature `[unsafe] fn(i16) [-> !]`
fn DefaultHandler(_irqn: i16, undef: u32) {}
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 c4914db..5eeb49f 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
@@ -7,5 +7,5 @@ extern crate panic_semihosting;
use cortex_m_rt::entry;
#[entry] //~ ERROR custom attribute panicked
-//~^ HELP `#[entry]` function must have signature `fn() -> !`
+//~^ HELP `#[entry]` function must have signature `[unsafe] fn() -> !`
fn foo() {}
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 88ffd34..18bbaed 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
@@ -7,5 +7,5 @@ extern crate panic_semihosting;
use cortex_m_rt::entry;
#[entry] //~ ERROR custom attribute panicked
-//~^ HELP `#[entry]` function must have signature `fn() -> !`
+//~^ HELP `#[entry]` function must have signature `[unsafe] fn() -> !`
fn foo(undef: i32) -> ! {}
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 0f2ddca..09b75e9 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
@@ -7,7 +7,7 @@ extern crate panic_semihosting;
use cortex_m_rt::entry;
#[entry] //~ ERROR custom attribute panicked
-//~^ HELP `#[entry]` function must have signature `fn() -> !`
-unsafe fn foo() -> ! {
+//~^ HELP `#[entry]` function must have signature `[unsafe] fn() -> !`
+extern "C" fn foo() -> ! {
loop {}
}
diff --git a/cortex-m-rt/tests/compile-fail/entry-bad-signature-4.rs b/cortex-m-rt/tests/compile-fail/entry-bad-signature-4.rs
deleted file mode 100644
index 2077f41..0000000
--- a/cortex-m-rt/tests/compile-fail/entry-bad-signature-4.rs
+++ /dev/null
@@ -1,13 +0,0 @@
-#![no_main]
-#![no_std]
-
-extern crate cortex_m_rt;
-extern crate panic_semihosting;
-
-use cortex_m_rt::entry;
-
-#[entry] //~ ERROR custom attribute panicked
-//~^ HELP `#[entry]` function must have signature `fn() -> !`
-extern "C" fn foo() -> ! {
- loop {}
-}
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 1f4b707..966493e 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
@@ -12,5 +12,5 @@ fn foo() -> ! {
}
#[exception] //~ ERROR custom attribute panicked
-//~^ HELP `#[exception]` functions other than `DefaultHandler` and `HardFault` must have signature `fn()`
+//~^ HELP `#[exception]` functions other than `DefaultHandler` and `HardFault` must have signature `[unsafe] fn() [-> !]`
fn SysTick(undef: u32) {}
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 7c61240..83fda5f 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
@@ -12,7 +12,7 @@ fn foo() -> ! {
}
#[exception] //~ ERROR custom attribute panicked
-//~^ HELP `HardFault` exception must have signature `fn(&ExceptionFrame) -> !`
+//~^ HELP `HardFault` exception must have signature `[unsafe] fn(&ExceptionFrame) -> !`
fn HardFault(_ef: &ExceptionFrame, undef: u32) -> ! {
loop {}
}