Skip to content

Commit fe1e56c

Browse files
bors[bot]japaric
andauthored
Merge #133
133: port compile fail tests to trybuild r=japaric a=japaric closes #127 Co-authored-by: Jorge Aparicio <jorge@japaric.io>
2 parents 5e42f0d + 1184bf4 commit fe1e56c

File tree

12 files changed

+184
-86
lines changed

12 files changed

+184
-86
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ matrix:
44
include:
55

66
# MSRV: Minimum Supported Rust Version
7-
- env: TARGET=x86_64-unknown-linux-gnu
7+
- env: TARGET=x86_64-unknown-linux-gnu MSRV=1
88
rust: 1.36.0
99
if: branch != master
1010

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ name = "heapless"
1919
repository = "https://github.com/japaric/heapless"
2020
version = "0.5.1"
2121

22-
[dev-dependencies]
22+
[target.x86_64-unknown-linux-gnu.dev-dependencies]
2323
scoped_threadpool = "0.1.8"
2424

2525
[dependencies]
@@ -31,3 +31,7 @@ hash32 = "0.1.0"
3131
version = "1"
3232
optional = true
3333
default-features = false
34+
35+
[features]
36+
# only for tests
37+
__trybuild = []

cfail/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
authors = ["Jorge Aparicio <jorge@japaric.io>"]
3+
edition = "2018"
4+
name = "cfail"
5+
publish = false
6+
version = "0.1.0"
7+
8+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
9+
10+
[dependencies]
11+
heapless = { path = ".." }
12+
trybuild = "1.0.18"

cfail/src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use trybuild::TestCases;
2+
3+
fn main() {
4+
let t = TestCases::new();
5+
t.compile_fail("ui/*.rs");
6+
}

cfail/ui/freeze.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use heapless::{consts, spsc::Queue};
2+
3+
fn main() {
4+
let mut q: Queue<u8, consts::U4> = Queue::new();
5+
6+
let (_p, mut _c) = q.split();
7+
q.enqueue(0).unwrap();
8+
_c.dequeue();
9+
}

cfail/ui/freeze.stderr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0499]: cannot borrow `q` as mutable more than once at a time
2+
--> $DIR/freeze.rs:7:5
3+
|
4+
6 | let (_p, mut _c) = q.split();
5+
| - first mutable borrow occurs here
6+
7 | q.enqueue(0).unwrap();
7+
| ^ second mutable borrow occurs here
8+
8 | _c.dequeue();
9+
| -- first borrow later used here

cfail/ui/not-send.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//! Collections of non-`Send`-able things are *not* `Send`
2+
3+
use core::marker::PhantomData;
4+
5+
use heapless::{
6+
consts,
7+
spsc::{Consumer, Producer, Queue},
8+
};
9+
10+
type NotSend = PhantomData<*const ()>;
11+
12+
fn is_send<T>()
13+
where
14+
T: Send,
15+
{
16+
}
17+
18+
fn main() {
19+
is_send::<Consumer<NotSend, consts::U4>>();
20+
is_send::<Producer<NotSend, consts::U4>>();
21+
is_send::<Queue<NotSend, consts::U4>>();
22+
is_send::<heapless::Vec<NotSend, consts::U4>>();
23+
}

cfail/ui/not-send.stderr

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
error[E0277]: `*const ()` cannot be sent between threads safely
2+
--> $DIR/not-send.rs:19:5
3+
|
4+
19 | is_send::<Consumer<NotSend, consts::U4>>();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
6+
|
7+
= help: within `std::marker::PhantomData<*const ()>`, the trait `std::marker::Send` is not implemented for `*const ()`
8+
= note: required because it appears within the type `std::marker::PhantomData<*const ()>`
9+
= note: required because of the requirements on the impl of `std::marker::Send` for `heapless::spsc::split::Consumer<'_, std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>`
10+
note: required by `is_send`
11+
--> $DIR/not-send.rs:12:1
12+
|
13+
12 | / fn is_send<T>()
14+
13 | | where
15+
14 | | T: Send,
16+
15 | | {
17+
16 | | }
18+
| |_^
19+
20+
error[E0277]: `*const ()` cannot be sent between threads safely
21+
--> $DIR/not-send.rs:20:5
22+
|
23+
20 | is_send::<Producer<NotSend, consts::U4>>();
24+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
25+
|
26+
= help: within `std::marker::PhantomData<*const ()>`, the trait `std::marker::Send` is not implemented for `*const ()`
27+
= note: required because it appears within the type `std::marker::PhantomData<*const ()>`
28+
= note: required because of the requirements on the impl of `std::marker::Send` for `heapless::spsc::split::Producer<'_, std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>`
29+
note: required by `is_send`
30+
--> $DIR/not-send.rs:12:1
31+
|
32+
12 | / fn is_send<T>()
33+
13 | | where
34+
14 | | T: Send,
35+
15 | | {
36+
16 | | }
37+
| |_^
38+
39+
error[E0277]: `*const ()` cannot be sent between threads safely
40+
--> $DIR/not-send.rs:21:5
41+
|
42+
21 | is_send::<Queue<NotSend, consts::U4>>();
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
44+
|
45+
= help: within `std::marker::PhantomData<*const ()>`, the trait `std::marker::Send` is not implemented for `*const ()`
46+
= note: required because it appears within the type `std::marker::PhantomData<*const ()>`
47+
= note: required because of the requirements on the impl of `std::marker::Send` for `generic_array::GenericArray<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>`
48+
= note: required because it appears within the type `std::mem::ManuallyDrop<generic_array::GenericArray<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>>`
49+
= note: required because it appears within the type `std::mem::MaybeUninit<generic_array::GenericArray<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>>`
50+
= note: required because it appears within the type `heapless::i::Queue<generic_array::GenericArray<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>>`
51+
= note: required because it appears within the type `heapless::spsc::Queue<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>`
52+
note: required by `is_send`
53+
--> $DIR/not-send.rs:12:1
54+
|
55+
12 | / fn is_send<T>()
56+
13 | | where
57+
14 | | T: Send,
58+
15 | | {
59+
16 | | }
60+
| |_^
61+
62+
error[E0277]: `*const ()` cannot be sent between threads safely
63+
--> $DIR/not-send.rs:22:5
64+
|
65+
22 | is_send::<heapless::Vec<NotSend, consts::U4>>();
66+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
67+
|
68+
= help: within `std::marker::PhantomData<*const ()>`, the trait `std::marker::Send` is not implemented for `*const ()`
69+
= note: required because it appears within the type `std::marker::PhantomData<*const ()>`
70+
= note: required because of the requirements on the impl of `std::marker::Send` for `generic_array::GenericArray<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>`
71+
= note: required because it appears within the type `std::mem::ManuallyDrop<generic_array::GenericArray<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>>`
72+
= note: required because it appears within the type `std::mem::MaybeUninit<generic_array::GenericArray<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>>`
73+
= note: required because it appears within the type `heapless::i::Vec<generic_array::GenericArray<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>>`
74+
= note: required because it appears within the type `heapless::vec::Vec<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>`
75+
note: required by `is_send`
76+
--> $DIR/not-send.rs:12:1
77+
|
78+
12 | / fn is_send<T>()
79+
13 | | where
80+
14 | | T: Send,
81+
15 | | {
82+
16 | | }
83+
| |_^

ci/script.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ main() {
88
cargo test --target $TARGET --features 'serde'
99
cargo test --target $TARGET --release --features 'serde'
1010

11+
if [ $MSRV = 1 ]; then
12+
cd cfail
13+
cargo run
14+
cd ..
15+
fi
16+
17+
1118
if [ $TRAVIS_RUST_VERSION = nightly ]; then
1219
export RUSTFLAGS="-Z sanitizer=thread"
1320
export RUST_TEST_THREADS=1
@@ -46,6 +53,10 @@ if [ -z ${TARGET-} ]; then
4653
TARGET=$(rustc -Vv | grep host | cut -d ' ' -f2)
4754
fi
4855

56+
if [ -z ${MSRV-} ]; then
57+
MSRV=0
58+
fi
59+
4960
if [ $TRAVIS_BRANCH != master ]; then
5061
main
5162
fi

src/cfail.rs

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)