From 9865a7246df289bfa5f65ba47c883c4ce3e108a9 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 9 Dec 2017 15:10:29 +0100 Subject: [PATCH 1/3] make resource proxies !Send --- macros/src/trans.rs | 8 +++-- tests/cfail/resource-not-send.rs | 52 ++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 tests/cfail/resource-not-send.rs diff --git a/macros/src/trans.rs b/macros/src/trans.rs index 96631d5d03..77eada4153 100644 --- a/macros/src/trans.rs +++ b/macros/src/trans.rs @@ -438,12 +438,14 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec) { items.push(quote! { #[allow(non_camel_case_types)] - pub struct #name { _0: () } + pub struct #name { _0: PhantomData<*const ()> } + + unsafe impl Sync for #name {} #[allow(unsafe_code)] impl #name { pub unsafe fn new() -> Self { - #name { _0: () } + #name { _0: PhantomData } } } }); @@ -455,6 +457,8 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec) { root.push(quote! { #[allow(unsafe_code)] mod _resource { + use core::marker::PhantomData; + #(#items)* } }) diff --git a/tests/cfail/resource-not-send.rs b/tests/cfail/resource-not-send.rs new file mode 100644 index 0000000000..333a3a5469 --- /dev/null +++ b/tests/cfail/resource-not-send.rs @@ -0,0 +1,52 @@ +#![deny(warnings)] +#![feature(const_fn)] +#![feature(proc_macro)] +#![no_std] + +extern crate cortex_m_rtfm as rtfm; +extern crate stm32f103xx; + +use rtfm::{app, Resource, Threshold}; + +app! { + device: stm32f103xx, + + resources: { + static SHARED: bool = false; + }, + + tasks: { + EXTI0: { + path: exti0, + priority: 1, + resources: [SHARED], + }, + + EXTI1: { + path: exti1, + priority: 2, + resources: [SHARED], + }, + }, +} + +fn init(_p: init::Peripherals, _r: init::Resources) {} + +fn idle() -> ! { + loop {} +} + +fn is_send(_: &T) where T: Send {} +fn is_sync(_: &T) where T: Sync {} + +fn exti0(_t: &mut Threshold, r: EXTI0::Resources) { + // OK + is_sync(&r.SHARED); + + // ERROR resource proxies are not `Send`able across tasks + is_send(&r.SHARED); + //~^ error the trait bound `*const (): core::marker::Send` is not satisfied +} + +fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) { +} From 8f23fdc9340167cf9d6d31a09705369c3b8acccb Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 9 Dec 2017 15:12:42 +0100 Subject: [PATCH 2/3] deny warnings and unsafe code in tests and examples --- examples/full-syntax.rs | 1 + examples/generics.rs | 1 + examples/late-resources.rs | 1 + examples/nested.rs | 1 + examples/one-task.rs | 1 + examples/preemption.rs | 1 + examples/two-tasks.rs | 1 + examples/zero-tasks.rs | 1 + tests/cfail/critical-section.rs | 1 + tests/cfail/duplicated-task.rs | 1 + tests/cfail/exception.rs | 1 + tests/cfail/idle.rs | 1 + tests/cfail/init.rs | 1 + tests/cfail/interrupt.rs | 1 + tests/cfail/late-resource-init.rs | 1 + tests/cfail/lock.rs | 1 + tests/cfail/peripheral-alias.rs | 1 + tests/cfail/priority-too-high.rs | 1 + tests/cfail/priority-too-low.rs | 1 + tests/cfail/resource-alias.rs | 1 + tests/cfail/resource-not-send.rs | 1 + tests/cfail/token-outlive.rs | 1 + tests/cfail/token-transfer.rs | 1 + tests/cfail/wrong-threshold.rs | 1 + 24 files changed, 24 insertions(+) diff --git a/examples/full-syntax.rs b/examples/full-syntax.rs index 9b6b394e5e..a8f79a7210 100644 --- a/examples/full-syntax.rs +++ b/examples/full-syntax.rs @@ -1,5 +1,6 @@ //! A showcase of the `app!` macro syntax #![deny(unsafe_code)] +#![deny(warnings)] #![feature(proc_macro)] #![no_std] diff --git a/examples/generics.rs b/examples/generics.rs index bc2fe7a81b..7cf9257b32 100644 --- a/examples/generics.rs +++ b/examples/generics.rs @@ -1,5 +1,6 @@ //! Working with resources in a generic fashion #![deny(unsafe_code)] +#![deny(warnings)] #![feature(proc_macro)] #![no_std] diff --git a/examples/late-resources.rs b/examples/late-resources.rs index 69a0ce8ae0..d42431c28a 100644 --- a/examples/late-resources.rs +++ b/examples/late-resources.rs @@ -1,6 +1,7 @@ //! Demonstrates initialization of resources in `init`. #![deny(unsafe_code)] +#![deny(warnings)] #![feature(proc_macro)] #![no_std] diff --git a/examples/nested.rs b/examples/nested.rs index 1c164f86b0..d2309f3d38 100644 --- a/examples/nested.rs +++ b/examples/nested.rs @@ -3,6 +3,7 @@ //! If you run this program you'll hit the breakpoints as indicated by the //! letters in the comments: A, then B, then C, etc. #![deny(unsafe_code)] +#![deny(warnings)] #![feature(proc_macro)] #![no_std] diff --git a/examples/one-task.rs b/examples/one-task.rs index 38f0135467..2e77676891 100644 --- a/examples/one-task.rs +++ b/examples/one-task.rs @@ -1,5 +1,6 @@ //! An application with one task #![deny(unsafe_code)] +#![deny(warnings)] #![feature(proc_macro)] #![no_std] diff --git a/examples/preemption.rs b/examples/preemption.rs index 5fda37d57e..98dde8d1f3 100644 --- a/examples/preemption.rs +++ b/examples/preemption.rs @@ -1,5 +1,6 @@ //! Two tasks running at *different* priorities with access to the same resource #![deny(unsafe_code)] +#![deny(warnings)] #![feature(proc_macro)] #![no_std] diff --git a/examples/two-tasks.rs b/examples/two-tasks.rs index 2200e5baa0..df6e784a97 100644 --- a/examples/two-tasks.rs +++ b/examples/two-tasks.rs @@ -1,5 +1,6 @@ //! Two tasks running at the *same* priority with access to the same resource #![deny(unsafe_code)] +#![deny(warnings)] #![feature(proc_macro)] #![no_std] diff --git a/examples/zero-tasks.rs b/examples/zero-tasks.rs index 58e6afc76c..b1ebab6f8e 100644 --- a/examples/zero-tasks.rs +++ b/examples/zero-tasks.rs @@ -1,5 +1,6 @@ //! Minimal example with zero tasks #![deny(unsafe_code)] +#![deny(warnings)] // IMPORTANT always include this feature gate #![feature(proc_macro)] #![no_std] diff --git a/tests/cfail/critical-section.rs b/tests/cfail/critical-section.rs index 728388e8b7..65719788cb 100644 --- a/tests/cfail/critical-section.rs +++ b/tests/cfail/critical-section.rs @@ -1,3 +1,4 @@ +#![deny(unsafe_code)] #![deny(warnings)] #![feature(const_fn)] #![feature(proc_macro)] diff --git a/tests/cfail/duplicated-task.rs b/tests/cfail/duplicated-task.rs index d91f09b664..82b7ac6306 100644 --- a/tests/cfail/duplicated-task.rs +++ b/tests/cfail/duplicated-task.rs @@ -1,3 +1,4 @@ +#![deny(unsafe_code)] #![deny(warnings)] #![feature(proc_macro)] #![no_std] diff --git a/tests/cfail/exception.rs b/tests/cfail/exception.rs index 065ccad81c..e2e749a27e 100644 --- a/tests/cfail/exception.rs +++ b/tests/cfail/exception.rs @@ -1,3 +1,4 @@ +#![deny(unsafe_code)] #![deny(warnings)] #![feature(proc_macro)] #![no_std] diff --git a/tests/cfail/idle.rs b/tests/cfail/idle.rs index a362ec7915..79fe99b0da 100644 --- a/tests/cfail/idle.rs +++ b/tests/cfail/idle.rs @@ -1,3 +1,4 @@ +#![deny(unsafe_code)] #![deny(warnings)] #![feature(proc_macro)] #![no_std] diff --git a/tests/cfail/init.rs b/tests/cfail/init.rs index 73643b111d..d2823e3f82 100644 --- a/tests/cfail/init.rs +++ b/tests/cfail/init.rs @@ -1,3 +1,4 @@ +#![deny(unsafe_code)] #![deny(warnings)] #![feature(proc_macro)] #![no_std] diff --git a/tests/cfail/interrupt.rs b/tests/cfail/interrupt.rs index b913d83202..e3ef2e8ffd 100644 --- a/tests/cfail/interrupt.rs +++ b/tests/cfail/interrupt.rs @@ -1,3 +1,4 @@ +#![deny(unsafe_code)] #![deny(warnings)] #![feature(proc_macro)] #![no_std] diff --git a/tests/cfail/late-resource-init.rs b/tests/cfail/late-resource-init.rs index cb37887f70..a1059f3403 100644 --- a/tests/cfail/late-resource-init.rs +++ b/tests/cfail/late-resource-init.rs @@ -1,3 +1,4 @@ +#![deny(unsafe_code)] #![deny(warnings)] #![feature(proc_macro)] #![no_std] diff --git a/tests/cfail/lock.rs b/tests/cfail/lock.rs index e0e37e0fb0..5630649aeb 100644 --- a/tests/cfail/lock.rs +++ b/tests/cfail/lock.rs @@ -1,3 +1,4 @@ +#![deny(unsafe_code)] #![deny(warnings)] #![feature(const_fn)] #![feature(proc_macro)] diff --git a/tests/cfail/peripheral-alias.rs b/tests/cfail/peripheral-alias.rs index 042666afaf..3528ec666b 100644 --- a/tests/cfail/peripheral-alias.rs +++ b/tests/cfail/peripheral-alias.rs @@ -1,3 +1,4 @@ +#![deny(unsafe_code)] #![deny(warnings)] #![feature(proc_macro)] #![no_std] diff --git a/tests/cfail/priority-too-high.rs b/tests/cfail/priority-too-high.rs index c139471df9..5c353770d2 100644 --- a/tests/cfail/priority-too-high.rs +++ b/tests/cfail/priority-too-high.rs @@ -1,3 +1,4 @@ +#![deny(unsafe_code)] #![deny(warnings)] #![feature(proc_macro)] #![no_std] diff --git a/tests/cfail/priority-too-low.rs b/tests/cfail/priority-too-low.rs index cefd34281a..2be2254deb 100644 --- a/tests/cfail/priority-too-low.rs +++ b/tests/cfail/priority-too-low.rs @@ -1,3 +1,4 @@ +#![deny(unsafe_code)] #![deny(warnings)] #![feature(proc_macro)] #![no_std] diff --git a/tests/cfail/resource-alias.rs b/tests/cfail/resource-alias.rs index 788af6f634..e1c73bb581 100644 --- a/tests/cfail/resource-alias.rs +++ b/tests/cfail/resource-alias.rs @@ -1,3 +1,4 @@ +#![deny(unsafe_code)] #![deny(warnings)] #![feature(proc_macro)] #![no_std] diff --git a/tests/cfail/resource-not-send.rs b/tests/cfail/resource-not-send.rs index 333a3a5469..c89c3d31cc 100644 --- a/tests/cfail/resource-not-send.rs +++ b/tests/cfail/resource-not-send.rs @@ -1,3 +1,4 @@ +#![deny(unsafe_code)] #![deny(warnings)] #![feature(const_fn)] #![feature(proc_macro)] diff --git a/tests/cfail/token-outlive.rs b/tests/cfail/token-outlive.rs index 31231b7289..819a3d1583 100644 --- a/tests/cfail/token-outlive.rs +++ b/tests/cfail/token-outlive.rs @@ -1,3 +1,4 @@ +#![deny(unsafe_code)] #![deny(warnings)] #![feature(const_fn)] #![feature(proc_macro)] diff --git a/tests/cfail/token-transfer.rs b/tests/cfail/token-transfer.rs index 38e878683b..bc6205217a 100644 --- a/tests/cfail/token-transfer.rs +++ b/tests/cfail/token-transfer.rs @@ -1,3 +1,4 @@ +#![deny(unsafe_code)] #![deny(warnings)] #![feature(const_fn)] #![feature(proc_macro)] diff --git a/tests/cfail/wrong-threshold.rs b/tests/cfail/wrong-threshold.rs index b97407150d..149f357da3 100644 --- a/tests/cfail/wrong-threshold.rs +++ b/tests/cfail/wrong-threshold.rs @@ -1,3 +1,4 @@ +#![deny(unsafe_code)] #![deny(warnings)] #![feature(proc_macro)] #![no_std] From d6c240f9743067c81e68adcf35c60304573db8b9 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 9 Dec 2017 15:25:46 +0100 Subject: [PATCH 3/3] also cache the Xargo directory --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 094e996c93..59a66b4a0a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,7 +51,10 @@ script: after_script: set +e -cache: cargo +cache: + cargo: true + directories: + - $HOME/.xargo before_cache: - chmod -R a+r $HOME/.cargo