Skip to content

Commit 6359e49

Browse files
committed
Auto merge of #511 - Amanieu:clone_from_index, r=Amanieu
Fix index calculation in panic guard of clone_from_impl Previously, it was possible for an uninitialized element to be dropped if all of the following occurred: - `clone_from` was called where `T: !Copy`. - The `clone` implementation of `T` panicked. - The first bucket of the source `HashMap` contained an entry. Fixes #510
2 parents 274c7bb + a5eddff commit 6359e49

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

.github/workflows/rust.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ jobs:
4343
- env:
4444
TARGET: ${{ matrix.target }}
4545
CHANNEL: ${{ matrix.channel }}
46-
CROSS: ${{ matrix.target != 'x86_64-unknown-linux-gnu' && '1' || '0' }}
47-
NO_STD: ${{ matrix.target == 'thumbv6m-none-eabi' && '1' || '0' }}
4846
run: sh ci/run.sh
4947
strategy:
5048
matrix:
@@ -56,9 +54,10 @@ jobs:
5654
armv7-unknown-linux-gnueabihf,
5755
aarch64-unknown-linux-gnu,
5856
thumbv6m-none-eabi,
59-
x86_64-pc-windows-gnu,
57+
# Disabled due to issues with cross-rs
58+
#x86_64-pc-windows-gnu,
6059
]
61-
channel: [1.72.0, nightly]
60+
channel: [1.74.0, nightly]
6261
include:
6362
- os: macos-latest
6463
target: x86_64-apple-darwin
@@ -68,10 +67,10 @@ jobs:
6867
channel: nightly
6968
- os: macos-latest
7069
target: x86_64-apple-darwin
71-
channel: 1.72.0
70+
channel: 1.74.0
7271
- os: windows-latest
7372
target: x86_64-pc-windows-msvc
74-
channel: 1.72.0
73+
channel: 1.74.0
7574
- os: ubuntu-latest
7675
target: x86_64-unknown-linux-gnu
7776
channel: beta

ci/run.sh

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,30 @@ set -ex
44

55
: "${TARGET?The TARGET environment variable must be set.}"
66

7+
case "${TARGET}" in
8+
x86_64-unknown-linux-gnu|x86_64-apple-darwin|x86_64-pc-windows-msvc)
9+
CROSS=0
10+
NO_STD=0
11+
;;
12+
thumbv6m-none-eabi)
13+
CROSS=1
14+
NO_STD=1
15+
;;
16+
*)
17+
CROSS=1
18+
NO_STD=0
19+
;;
20+
esac
21+
22+
CARGO=cargo
23+
if [ "${CROSS}" = "1" ]; then
24+
export CARGO_NET_RETRY=5
25+
export CARGO_NET_TIMEOUT=10
26+
27+
cargo install --locked cross
28+
CARGO=cross
29+
fi
30+
731
if [ "${NO_STD}" = "1" ]; then
832
# Unfortunately serde currently doesn't work without std due to a cargo bug.
933
FEATURES="rustc-internal-api"
@@ -12,20 +36,12 @@ else
1236
FEATURES="rustc-internal-api,serde,rayon,raw"
1337
OP="test"
1438
fi
39+
1540
if [ "${CHANNEL}" = "nightly" ]; then
1641
FEATURES="${FEATURES},nightly"
1742
export RUSTFLAGS="$RUSTFLAGS -D warnings"
1843
fi
1944

20-
CARGO=cargo
21-
if [ "${CROSS}" = "1" ]; then
22-
export CARGO_NET_RETRY=5
23-
export CARGO_NET_TIMEOUT=10
24-
25-
cargo install --locked cross
26-
CARGO=cross
27-
fi
28-
2945
# Make sure we can compile without the default hasher
3046
"${CARGO}" -vv build --target="${TARGET}" --no-default-features
3147
"${CARGO}" -vv build --target="${TARGET}" --release --no-default-features

src/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{Equivalent, TryReserveError};
55
use core::borrow::Borrow;
66
use core::fmt::{self, Debug};
77
use core::hash::{BuildHasher, Hash};
8-
use core::iter::{FromIterator, FusedIterator};
8+
use core::iter::FusedIterator;
99
use core::marker::PhantomData;
1010
use core::mem;
1111
use core::ops::Index;

src/raw/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,7 +3582,7 @@ impl<T: Clone, A: Allocator + Clone> RawTable<T, A> {
35823582
// cloned so far.
35833583
let mut guard = guard((0, &mut *self), |(index, self_)| {
35843584
if T::NEEDS_DROP {
3585-
for i in 0..=*index {
3585+
for i in 0..*index {
35863586
if self_.is_bucket_full(i) {
35873587
self_.bucket(i).drop();
35883588
}
@@ -3596,7 +3596,7 @@ impl<T: Clone, A: Allocator + Clone> RawTable<T, A> {
35963596
to.write(from.as_ref().clone());
35973597

35983598
// Update the index in case we need to unwind.
3599-
guard.0 = index;
3599+
guard.0 = index + 1;
36003600
}
36013601

36023602
// Successfully cloned all items, no need to clean up.

src/set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{Equivalent, TryReserveError};
44
use alloc::borrow::ToOwned;
55
use core::fmt;
66
use core::hash::{BuildHasher, Hash};
7-
use core::iter::{Chain, FromIterator, FusedIterator};
7+
use core::iter::{Chain, FusedIterator};
88
use core::ops::{BitAnd, BitOr, BitXor, Sub};
99

1010
use super::map::{self, DefaultHashBuilder, HashMap, Keys};

0 commit comments

Comments
 (0)