Skip to content

Commit f290006

Browse files
authored
Merge pull request #402 from rust-embedded/fix-indexmap
Fix IndexMap entry API, fix CI.
2 parents 8380165 + 2be6a9a commit f290006

File tree

6 files changed

+56
-50
lines changed

6 files changed

+56
-50
lines changed

.github/workflows/build.yml

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,42 @@ jobs:
4949
- name: Run miri
5050
run: MIRIFLAGS=-Zmiri-ignore-leaks cargo miri test
5151

52+
# Run cargo test
53+
test:
54+
name: test
55+
runs-on: ubuntu-latest
56+
steps:
57+
- name: Checkout
58+
uses: actions/checkout@v4
59+
60+
- name: Cache cargo dependencies
61+
uses: actions/cache@v3
62+
with:
63+
path: |
64+
- ~/.cargo/bin/
65+
- ~/.cargo/registry/index/
66+
- ~/.cargo/registry/cache/
67+
- ~/.cargo/git/db/
68+
key: ${{ runner.OS }}-cargo-${{ hashFiles('**/Cargo.lock') }}
69+
restore-keys: |
70+
${{ runner.OS }}-cargo-
71+
72+
- name: Cache build output dependencies
73+
uses: actions/cache@v3
74+
with:
75+
path: target
76+
key: ${{ runner.OS }}-build-${{ hashFiles('**/Cargo.lock') }}
77+
restore-keys: |
78+
${{ runner.OS }}-build-
79+
80+
- name: Install Rust
81+
uses: dtolnay/rust-toolchain@master
82+
with:
83+
toolchain: stable
84+
85+
- name: Run cargo test
86+
run: cargo test
87+
5288
# Run cargo fmt --check
5389
style:
5490
name: style
@@ -169,11 +205,6 @@ jobs:
169205
target:
170206
- x86_64-unknown-linux-gnu
171207
- i686-unknown-linux-musl
172-
toolchain:
173-
- stable
174-
- nightly
175-
features:
176-
- serde
177208
buildtype:
178209
- ""
179210
- "--release"
@@ -203,14 +234,14 @@ jobs:
203234
${{ runner.OS }}-build-${{ hashFiles('**/Cargo.lock') }}
204235
${{ runner.OS }}-build-
205236
206-
- name: Install Rust ${{ matrix.toolchain }} with target (${{ matrix.target }})
237+
- name: Install Rust with target (${{ matrix.target }})
207238
uses: dtolnay/rust-toolchain@master
208239
with:
209-
toolchain: ${{ matrix.toolchain }}
240+
toolchain: stable
210241
targets: ${{ matrix.target }}
211242

212243
- name: cargo test
213-
run: cargo test --test cpass --target=${{ matrix.target }} --features=${{ matrix.features }} ${{ matrix.buildtype }}
244+
run: cargo test --test cpass --target=${{ matrix.target }} --features=serde ${{ matrix.buildtype }}
214245

215246
# Run test suite for UI
216247
testtsan:
@@ -220,8 +251,6 @@ jobs:
220251
matrix:
221252
target:
222253
- x86_64-unknown-linux-gnu
223-
toolchain:
224-
- nightly
225254
buildtype:
226255
- ""
227256
- "--release"
@@ -249,10 +278,10 @@ jobs:
249278
restore-keys: |
250279
${{ runner.OS }}-build-
251280
252-
- name: Install Rust ${{ matrix.toolchain }} with target (${{ matrix.target }})
281+
- name: Install Rust nightly with target (${{ matrix.target }})
253282
uses: dtolnay/rust-toolchain@master
254283
with:
255-
toolchain: ${{ matrix.toolchain }}
284+
toolchain: nightly
256285
target: ${{ matrix.target }}
257286
components: rust-src
258287

@@ -302,23 +331,3 @@ jobs:
302331

303332
- name: Run cargo
304333
run: cargo run
305-
306-
# Refs: https://github.com/rust-lang/crater/blob/9ab6f9697c901c4a44025cf0a39b73ad5b37d198/.github/workflows/bors.yml#L125-L149
307-
#
308-
# ALL THE PREVIOUS JOBS NEEDS TO BE ADDED TO THE `needs` SECTION OF THIS JOB!
309-
310-
ci-success:
311-
name: ci
312-
if: github.event_name == 'push' && success()
313-
needs:
314-
- style
315-
- check
316-
- doc
317-
- testcpass
318-
- testtsan
319-
- testcfail
320-
- testmiri
321-
runs-on: ubuntu-latest
322-
steps:
323-
- name: Mark the job as a success
324-
run: exit 0

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
4343
### Fixed
4444

4545
- Fixed a `dropping_references` warning in `LinearMap`.
46+
- Fixed IndexMap entry API returning wrong slot after an insert on vacant entry. (#360)
4647

4748
### Removed
4849

src/de.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{
2-
binary_heap::Kind as BinaryHeapKind, BinaryHeap, Deque, IndexMap, IndexSet, LinearMap, String, Vec,
2+
binary_heap::Kind as BinaryHeapKind, BinaryHeap, Deque, IndexMap, IndexSet, LinearMap, String,
3+
Vec,
34
};
45
use core::{
56
fmt,

src/indexmap.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,9 @@ where
209209
// robin hood: steal the spot if it's better for us
210210
let index = self.entries.len();
211211
unsafe { self.entries.push_unchecked(Bucket { hash, key, value }) };
212+
Self::insert_phase_2(&mut self.indices, probe, Pos::new(index, hash));
212213
return Insert::Success(Inserted {
213-
index: Self::insert_phase_2(
214-
&mut self.indices,
215-
probe,
216-
Pos::new(index, hash),
217-
),
214+
index,
218215
old_value: None,
219216
});
220217
} else if entry_hash == hash && unsafe { self.entries.get_unchecked(i).key == key }
@@ -1372,7 +1369,7 @@ mod tests {
13721369
panic!("Entry found when empty");
13731370
}
13741371
Entry::Vacant(v) => {
1375-
v.insert(value).unwrap();
1372+
assert_eq!(value, *v.insert(value).unwrap());
13761373
}
13771374
};
13781375
assert_eq!(value, *src.get(&key).unwrap())
@@ -1472,7 +1469,7 @@ mod tests {
14721469
panic!("Entry found before insert");
14731470
}
14741471
Entry::Vacant(v) => {
1475-
v.insert(i).unwrap();
1472+
assert_eq!(i, *v.insert(i).unwrap());
14761473
}
14771474
}
14781475
}

src/ser.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use core::hash::{BuildHasher, Hash};
22

33
use crate::{
4-
binary_heap::Kind as BinaryHeapKind, BinaryHeap, Deque, IndexMap, IndexSet, LinearMap, String, Vec,
4+
binary_heap::Kind as BinaryHeapKind, BinaryHeap, Deque, IndexMap, IndexSet, LinearMap, String,
5+
Vec,
56
};
67
use serde::ser::{Serialize, SerializeMap, SerializeSeq, Serializer};
78

src/string.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ impl<const N: usize> String<N> {
350350
/// ```
351351
/// use heapless::String;
352352
///
353-
/// let mut s: String<8> = String::from("foo");
353+
/// let mut s: String<8> = String::try_from("foo").unwrap();
354354
///
355355
/// assert_eq!(s.remove(0), 'f');
356356
/// assert_eq!(s.remove(1), 'o');
@@ -365,12 +365,9 @@ impl<const N: usize> String<N> {
365365

366366
let next = index + ch.len_utf8();
367367
let len = self.len();
368+
let ptr = self.vec.as_mut_ptr();
368369
unsafe {
369-
core::ptr::copy(
370-
self.vec.as_ptr().add(next),
371-
self.vec.as_mut_ptr().add(index),
372-
len - next,
373-
);
370+
core::ptr::copy(ptr.add(next), ptr.add(index), len - next);
374371
self.vec.set_len(len - (next - index));
375372
}
376373
ch
@@ -842,14 +839,14 @@ mod tests {
842839

843840
#[test]
844841
fn remove() {
845-
let mut s: String<8> = String::from("foo");
842+
let mut s: String<8> = String::try_from("foo").unwrap();
846843
assert_eq!(s.remove(0), 'f');
847844
assert_eq!(s.as_str(), "oo");
848845
}
849846

850847
#[test]
851848
fn remove_uenc() {
852-
let mut s: String<8> = String::from("ĝėēƶ");
849+
let mut s: String<8> = String::try_from("ĝėēƶ").unwrap();
853850
assert_eq!(s.remove(2), 'ė');
854851
assert_eq!(s.remove(2), 'ē');
855852
assert_eq!(s.remove(2), 'ƶ');
@@ -858,7 +855,7 @@ mod tests {
858855

859856
#[test]
860857
fn remove_uenc_combo_characters() {
861-
let mut s: String<8> = String::from("héy");
858+
let mut s: String<8> = String::try_from("héy").unwrap();
862859
assert_eq!(s.remove(2), '\u{0301}');
863860
assert_eq!(s.as_str(), "hey");
864861
}

0 commit comments

Comments
 (0)