Skip to content

Commit 40468da

Browse files
authored
Merge pull request #388 from newAM/fix-linear-map-drop
Fix dropping_references warning
2 parents 644653b + a4e8f82 commit 40468da

File tree

5 files changed

+83
-46
lines changed

5 files changed

+83
-46
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
branches: [main]
55
push:
66
branches: [staging, trying]
7+
workflow_dispatch:
78

89
env:
910
CARGO_TERM_COLOR: always
@@ -282,6 +283,7 @@ jobs:
282283
with:
283284
toolchain: ${{ matrix.toolchain }}
284285
target: ${{ matrix.target }}
286+
components: rust-src
285287
override: true
286288

287289
- name: Export variables
@@ -294,7 +296,7 @@ jobs:
294296
with:
295297
use-cross: false
296298
command: test
297-
args: --test tsan --target=${{ matrix.target }} --features=${{ matrix.features }} ${{ matrix.buildtype }} -- --test-threads=1
299+
args: -Zbuild-std --test tsan --target=${{ matrix.target }} --features=${{ matrix.features }} ${{ matrix.buildtype }} -- --test-threads=1
298300

299301
# Run cfail tests on MSRV
300302
testcfail:
@@ -338,8 +340,6 @@ jobs:
338340
- name: Run cargo
339341
run: cargo run
340342

341-
342-
343343
# Refs: https://github.com/rust-lang/crater/blob/9ab6f9697c901c4a44025cf0a39b73ad5b37d198/.github/workflows/bors.yml#L125-L149
344344
#
345345
# ALL THE PREVIOUS JOBS NEEDS TO BE ADDED TO THE `needs` SECTION OF THIS JOB!

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3636

3737
### Fixed
3838

39+
- Fixed a `dropping_references` warning in `LinearMap`.
40+
3941
### Removed
4042

4143
- [breaking-change] this crate no longer has a Minimum Supported Rust Version (MSRV) guarantee and

cfail/ui/freeze.stderr

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

cfail/ui/not-send.stderr

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,123 @@
11
error[E0277]: `*const ()` cannot be sent between threads safely
2-
--> $DIR/not-send.rs:19:15
2+
--> ui/not-send.rs:19:15
33
|
44
19 | is_send::<Consumer<NotSend, 4>>();
55
| ^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
66
|
77
= help: within `PhantomData<*const ()>`, the trait `Send` is not implemented for `*const ()`
8-
= note: required because it appears within the type `PhantomData<*const ()>`
8+
note: required because it appears within the type `PhantomData<*const ()>`
9+
--> $RUST/core/src/marker.rs
910
= note: required for `Consumer<'_, PhantomData<*const ()>, 4>` to implement `Send`
1011
note: required by a bound in `is_send`
11-
--> $DIR/not-send.rs:14:8
12+
--> ui/not-send.rs:14:8
1213
|
1314
12 | fn is_send<T>()
14-
| ------- required by a bound in this
15+
| ------- required by a bound in this function
1516
13 | where
1617
14 | T: Send,
1718
| ^^^^ required by this bound in `is_send`
1819

1920
error[E0277]: `*const ()` cannot be sent between threads safely
20-
--> $DIR/not-send.rs:20:15
21+
--> ui/not-send.rs:20:15
2122
|
2223
20 | is_send::<Producer<NotSend, 4>>();
2324
| ^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
2425
|
2526
= help: within `PhantomData<*const ()>`, the trait `Send` is not implemented for `*const ()`
26-
= note: required because it appears within the type `PhantomData<*const ()>`
27+
note: required because it appears within the type `PhantomData<*const ()>`
28+
--> $RUST/core/src/marker.rs
2729
= note: required for `Producer<'_, PhantomData<*const ()>, 4>` to implement `Send`
2830
note: required by a bound in `is_send`
29-
--> $DIR/not-send.rs:14:8
31+
--> ui/not-send.rs:14:8
3032
|
3133
12 | fn is_send<T>()
32-
| ------- required by a bound in this
34+
| ------- required by a bound in this function
3335
13 | where
3436
14 | T: Send,
3537
| ^^^^ required by this bound in `is_send`
3638

3739
error[E0277]: `*const ()` cannot be sent between threads safely
38-
--> $DIR/not-send.rs:21:15
40+
--> ui/not-send.rs:21:15
3941
|
4042
21 | is_send::<Queue<NotSend, 4>>();
4143
| ^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
4244
|
4345
= help: within `Queue<PhantomData<*const ()>, 4>`, the trait `Send` is not implemented for `*const ()`
44-
= note: required because it appears within the type `PhantomData<*const ()>`
45-
= note: required because it appears within the type `ManuallyDrop<PhantomData<*const ()>>`
46-
= note: required because it appears within the type `MaybeUninit<PhantomData<*const ()>>`
47-
= note: required because it appears within the type `UnsafeCell<MaybeUninit<PhantomData<*const ()>>>`
46+
note: required because it appears within the type `PhantomData<*const ()>`
47+
--> $RUST/core/src/marker.rs
48+
note: required because it appears within the type `ManuallyDrop<PhantomData<*const ()>>`
49+
--> $RUST/core/src/mem/manually_drop.rs
50+
note: required because it appears within the type `MaybeUninit<PhantomData<*const ()>>`
51+
--> $RUST/core/src/mem/maybe_uninit.rs
52+
note: required because it appears within the type `UnsafeCell<MaybeUninit<PhantomData<*const ()>>>`
53+
--> $RUST/core/src/cell.rs
4854
= note: required because it appears within the type `[UnsafeCell<MaybeUninit<PhantomData<*const ()>>>; 4]`
49-
= note: required because it appears within the type `Queue<PhantomData<*const ()>, 4>`
55+
note: required because it appears within the type `Queue<PhantomData<*const ()>, 4>`
56+
--> $HEAPLESS/src/spsc.rs
57+
|
58+
| pub struct Queue<T, const N: usize> {
59+
| ^^^^^
5060
note: required by a bound in `is_send`
51-
--> $DIR/not-send.rs:14:8
61+
--> ui/not-send.rs:14:8
5262
|
5363
12 | fn is_send<T>()
54-
| ------- required by a bound in this
64+
| ------- required by a bound in this function
5565
13 | where
5666
14 | T: Send,
5767
| ^^^^ required by this bound in `is_send`
5868

5969
error[E0277]: `*const ()` cannot be sent between threads safely
60-
--> $DIR/not-send.rs:22:15
70+
--> ui/not-send.rs:22:15
6171
|
6272
22 | is_send::<Vec<NotSend, 4>>();
6373
| ^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
6474
|
6575
= help: within `heapless::Vec<PhantomData<*const ()>, 4>`, the trait `Send` is not implemented for `*const ()`
66-
= note: required because it appears within the type `PhantomData<*const ()>`
67-
= note: required because it appears within the type `ManuallyDrop<PhantomData<*const ()>>`
68-
= note: required because it appears within the type `MaybeUninit<PhantomData<*const ()>>`
76+
note: required because it appears within the type `PhantomData<*const ()>`
77+
--> $RUST/core/src/marker.rs
78+
note: required because it appears within the type `ManuallyDrop<PhantomData<*const ()>>`
79+
--> $RUST/core/src/mem/manually_drop.rs
80+
note: required because it appears within the type `MaybeUninit<PhantomData<*const ()>>`
81+
--> $RUST/core/src/mem/maybe_uninit.rs
6982
= note: required because it appears within the type `[MaybeUninit<PhantomData<*const ()>>; 4]`
70-
= note: required because it appears within the type `heapless::Vec<PhantomData<*const ()>, 4>`
83+
note: required because it appears within the type `Vec<PhantomData<*const ()>, 4>`
84+
--> $HEAPLESS/src/vec.rs
85+
|
86+
| pub struct Vec<T, const N: usize> {
87+
| ^^^
7188
note: required by a bound in `is_send`
72-
--> $DIR/not-send.rs:14:8
89+
--> ui/not-send.rs:14:8
7390
|
7491
12 | fn is_send<T>()
75-
| ------- required by a bound in this
92+
| ------- required by a bound in this function
7693
13 | where
7794
14 | T: Send,
7895
| ^^^^ required by this bound in `is_send`
7996

8097
error[E0277]: `*const ()` cannot be sent between threads safely
81-
--> $DIR/not-send.rs:23:15
98+
--> ui/not-send.rs:23:15
8299
|
83100
23 | is_send::<HistoryBuffer<NotSend, 4>>();
84101
| ^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
85102
|
86103
= help: within `HistoryBuffer<PhantomData<*const ()>, 4>`, the trait `Send` is not implemented for `*const ()`
87-
= note: required because it appears within the type `PhantomData<*const ()>`
88-
= note: required because it appears within the type `ManuallyDrop<PhantomData<*const ()>>`
89-
= note: required because it appears within the type `MaybeUninit<PhantomData<*const ()>>`
104+
note: required because it appears within the type `PhantomData<*const ()>`
105+
--> $RUST/core/src/marker.rs
106+
note: required because it appears within the type `ManuallyDrop<PhantomData<*const ()>>`
107+
--> $RUST/core/src/mem/manually_drop.rs
108+
note: required because it appears within the type `MaybeUninit<PhantomData<*const ()>>`
109+
--> $RUST/core/src/mem/maybe_uninit.rs
90110
= note: required because it appears within the type `[MaybeUninit<PhantomData<*const ()>>; 4]`
91-
= note: required because it appears within the type `HistoryBuffer<PhantomData<*const ()>, 4>`
111+
note: required because it appears within the type `HistoryBuffer<PhantomData<*const ()>, 4>`
112+
--> $HEAPLESS/src/histbuf.rs
113+
|
114+
| pub struct HistoryBuffer<T, const N: usize> {
115+
| ^^^^^^^^^^^^^
92116
note: required by a bound in `is_send`
93-
--> $DIR/not-send.rs:14:8
117+
--> ui/not-send.rs:14:8
94118
|
95119
12 | fn is_send<T>()
96-
| ------- required by a bound in this
120+
| ------- required by a bound in this function
97121
13 | where
98122
14 | T: Send,
99123
| ^^^^ required by this bound in `is_send`

src/linear_map.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -461,15 +461,6 @@ impl<'a, K, V> Clone for Iter<'a, K, V> {
461461
}
462462
}
463463

464-
impl<K, V, const N: usize> Drop for LinearMap<K, V, N> {
465-
fn drop(&mut self) {
466-
// heapless::Vec implements drop right?
467-
drop(&self.buffer);
468-
// original code below
469-
// unsafe { ptr::drop_in_place(self.buffer.as_mut_slice()) }
470-
}
471-
}
472-
473464
pub struct IterMut<'a, K, V> {
474465
iter: slice::IterMut<'a, (K, V)>,
475466
}
@@ -540,5 +531,25 @@ mod test {
540531
}
541532
}
542533

543-
// TODO: drop test
534+
#[test]
535+
fn drop() {
536+
droppable!();
537+
538+
{
539+
let mut v: LinearMap<i32, Droppable, 2> = LinearMap::new();
540+
v.insert(0, Droppable::new()).ok().unwrap();
541+
v.insert(1, Droppable::new()).ok().unwrap();
542+
v.remove(&1).unwrap();
543+
}
544+
545+
assert_eq!(Droppable::count(), 0);
546+
547+
{
548+
let mut v: LinearMap<i32, Droppable, 2> = LinearMap::new();
549+
v.insert(0, Droppable::new()).ok().unwrap();
550+
v.insert(1, Droppable::new()).ok().unwrap();
551+
}
552+
553+
assert_eq!(Droppable::count(), 0);
554+
}
544555
}

0 commit comments

Comments
 (0)