Skip to content

Commit c059aec

Browse files
bors[bot]taiki-e
andauthored
Merge #877
877: Bump MSRV to Rust 1.38 r=taiki-e a=taiki-e It was released [nearly 3 years ago](https://blog.rust-lang.org/2019/09/26/Rust-1.38.0.html) and meets our MSRV policy. This allows using const_in_array_repeat_expressions (rust-lang/rust#49147) and `<pointer>.cast()`. Co-authored-by: Taiki Endo <[email protected]>
2 parents 99b14b1 + 6ac1232 commit c059aec

File tree

27 files changed

+89
-157
lines changed

27 files changed

+89
-157
lines changed

.clippy.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
msrv = "1.36"
1+
msrv = "1.38"

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ jobs:
3030
fail-fast: false
3131
matrix:
3232
include:
33-
- rust: 1.36.0
33+
- rust: '1.38'
3434
os: ubuntu-latest
35-
- rust: 1.36.0
35+
- rust: '1.38'
3636
os: windows-latest
3737
- rust: stable
3838
os: ubuntu-latest
@@ -75,7 +75,7 @@ jobs:
7575
fail-fast: false
7676
matrix:
7777
rust:
78-
- 1.36.0
78+
- '1.38'
7979
- nightly
8080
runs-on: ubuntu-latest
8181
steps:

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name = "crossbeam"
66
# - Create "crossbeam-X.Y.Z" git tag
77
version = "0.8.1"
88
edition = "2018"
9-
rust-version = "1.36"
9+
rust-version = "1.38"
1010
license = "MIT OR Apache-2.0"
1111
repository = "https://github.com/crossbeam-rs/crossbeam"
1212
homepage = "https://github.com/crossbeam-rs/crossbeam"

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ https://github.com/crossbeam-rs/crossbeam#license)
88
https://crates.io/crates/crossbeam)
99
[![Documentation](https://docs.rs/crossbeam/badge.svg)](
1010
https://docs.rs/crossbeam)
11-
[![Rust 1.36+](https://img.shields.io/badge/rust-1.36+-lightgray.svg)](
11+
[![Rust 1.38+](https://img.shields.io/badge/rust-1.38+-lightgray.svg)](
1212
https://www.rust-lang.org)
1313
[![chat](https://img.shields.io/discord/569610676205781012.svg?logo=discord)](https://discord.com/invite/JXYwgWZ)
1414

@@ -94,7 +94,7 @@ crossbeam = "0.8"
9494

9595
Crossbeam supports stable Rust releases going back at least six months,
9696
and every time the minimum supported Rust version is increased, a new minor
97-
version is released. Currently, the minimum supported Rust version is 1.36.
97+
version is released. Currently, the minimum supported Rust version is 1.38.
9898

9999
## Contributing
100100

crossbeam-channel/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name = "crossbeam-channel"
66
# - Create "crossbeam-channel-X.Y.Z" git tag
77
version = "0.5.5"
88
edition = "2018"
9-
rust-version = "1.36"
9+
rust-version = "1.38"
1010
license = "MIT OR Apache-2.0"
1111
repository = "https://github.com/crossbeam-rs/crossbeam"
1212
homepage = "https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-channel"

crossbeam-channel/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-channel#license)
88
https://crates.io/crates/crossbeam-channel)
99
[![Documentation](https://docs.rs/crossbeam-channel/badge.svg)](
1010
https://docs.rs/crossbeam-channel)
11-
[![Rust 1.36+](https://img.shields.io/badge/rust-1.36+-lightgray.svg)](
11+
[![Rust 1.38+](https://img.shields.io/badge/rust-1.38+-lightgray.svg)](
1212
https://www.rust-lang.org)
1313
[![chat](https://img.shields.io/discord/569610676205781012.svg?logo=discord)](https://discord.com/invite/JXYwgWZ)
1414

@@ -48,7 +48,7 @@ crossbeam-channel = "0.5"
4848

4949
Crossbeam Channel supports stable Rust releases going back at least six months,
5050
and every time the minimum supported Rust version is increased, a new minor
51-
version is released. Currently, the minimum supported Rust version is 1.36.
51+
version is released. Currently, the minimum supported Rust version is 1.38.
5252

5353
## License
5454

crossbeam-channel/src/flavors/array.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl<T> Channel<T> {
216216
return Err(msg);
217217
}
218218

219-
let slot: &Slot<T> = &*(token.array.slot as *const Slot<T>);
219+
let slot: &Slot<T> = &*token.array.slot.cast::<Slot<T>>();
220220

221221
// Write the message into the slot and update the stamp.
222222
slot.msg.get().write(MaybeUninit::new(msg));
@@ -307,7 +307,7 @@ impl<T> Channel<T> {
307307
return Err(());
308308
}
309309

310-
let slot: &Slot<T> = &*(token.array.slot as *const Slot<T>);
310+
let slot: &Slot<T> = &*token.array.slot.cast::<Slot<T>>();
311311

312312
// Read the message from the slot and update the stamp.
313313
let msg = slot.msg.get().read().assume_init();

crossbeam-channel/src/flavors/list.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ struct Slot<T> {
4949
}
5050

5151
impl<T> Slot<T> {
52+
const UNINIT: Self = Self {
53+
msg: UnsafeCell::new(MaybeUninit::uninit()),
54+
state: AtomicUsize::new(0),
55+
};
56+
5257
/// Waits until a message is written into the slot.
5358
fn wait_write(&self) {
5459
let backoff = Backoff::new();
@@ -72,13 +77,10 @@ struct Block<T> {
7277
impl<T> Block<T> {
7378
/// Creates an empty block.
7479
fn new() -> Block<T> {
75-
// SAFETY: This is safe because:
76-
// [1] `Block::next` (AtomicPtr) may be safely zero initialized.
77-
// [2] `Block::slots` (Array) may be safely zero initialized because of [3, 4].
78-
// [3] `Slot::msg` (UnsafeCell) may be safely zero initialized because it
79-
// holds a MaybeUninit.
80-
// [4] `Slot::state` (AtomicUsize) may be safely zero initialized.
81-
unsafe { MaybeUninit::zeroed().assume_init() }
80+
Self {
81+
next: AtomicPtr::new(ptr::null_mut()),
82+
slots: [Slot::UNINIT; BLOCK_CAP],
83+
}
8284
}
8385

8486
/// Waits until the next pointer is set.
@@ -283,7 +285,7 @@ impl<T> Channel<T> {
283285
}
284286

285287
// Write the message into the slot.
286-
let block = token.list.block as *mut Block<T>;
288+
let block = token.list.block.cast::<Block<T>>();
287289
let offset = token.list.offset;
288290
let slot = (*block).slots.get_unchecked(offset);
289291
slot.msg.get().write(MaybeUninit::new(msg));

crossbeam-channel/src/flavors/zero.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl<T> Channel<T> {
190190
// heap-allocated packet.
191191
packet.wait_ready();
192192
let msg = packet.msg.get().replace(None).unwrap();
193-
drop(Box::from_raw(token.zero.0 as *mut Packet<T>));
193+
drop(Box::from_raw(token.zero.0.cast::<Packet<T>>()));
194194
Ok(msg)
195195
}
196196
}
@@ -409,15 +409,15 @@ impl<T> SelectHandle for Receiver<'_, T> {
409409
let mut inner = self.0.inner.lock().unwrap();
410410
inner
411411
.receivers
412-
.register_with_packet(oper, packet as *mut (), cx);
412+
.register_with_packet(oper, packet.cast::<()>(), cx);
413413
inner.senders.notify();
414414
inner.senders.can_select() || inner.is_disconnected
415415
}
416416

417417
fn unregister(&self, oper: Operation) {
418418
if let Some(operation) = self.0.inner.lock().unwrap().receivers.unregister(oper) {
419419
unsafe {
420-
drop(Box::from_raw(operation.packet as *mut Packet<T>));
420+
drop(Box::from_raw(operation.packet.cast::<Packet<T>>()));
421421
}
422422
}
423423
}
@@ -459,15 +459,15 @@ impl<T> SelectHandle for Sender<'_, T> {
459459
let mut inner = self.0.inner.lock().unwrap();
460460
inner
461461
.senders
462-
.register_with_packet(oper, packet as *mut (), cx);
462+
.register_with_packet(oper, packet.cast::<()>(), cx);
463463
inner.receivers.notify();
464464
inner.receivers.can_select() || inner.is_disconnected
465465
}
466466

467467
fn unregister(&self, oper: Operation) {
468468
if let Some(operation) = self.0.inner.lock().unwrap().senders.unregister(oper) {
469469
unsafe {
470-
drop(Box::from_raw(operation.packet as *mut Packet<T>));
470+
drop(Box::from_raw(operation.packet.cast::<Packet<T>>()));
471471
}
472472
}
473473
}

crossbeam-deque/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name = "crossbeam-deque"
66
# - Create "crossbeam-deque-X.Y.Z" git tag
77
version = "0.8.1"
88
edition = "2018"
9-
rust-version = "1.36"
9+
rust-version = "1.38"
1010
license = "MIT OR Apache-2.0"
1111
repository = "https://github.com/crossbeam-rs/crossbeam"
1212
homepage = "https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-deque"

crossbeam-deque/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-deque#license)
88
https://crates.io/crates/crossbeam-deque)
99
[![Documentation](https://docs.rs/crossbeam-deque/badge.svg)](
1010
https://docs.rs/crossbeam-deque)
11-
[![Rust 1.36+](https://img.shields.io/badge/rust-1.36+-lightgray.svg)](
11+
[![Rust 1.38+](https://img.shields.io/badge/rust-1.38+-lightgray.svg)](
1212
https://www.rust-lang.org)
1313
[![chat](https://img.shields.io/discord/569610676205781012.svg?logo=discord)](https://discord.com/invite/JXYwgWZ)
1414

@@ -28,7 +28,7 @@ crossbeam-deque = "0.8"
2828

2929
Crossbeam Deque supports stable Rust releases going back at least six months,
3030
and every time the minimum supported Rust version is increased, a new minor
31-
version is released. Currently, the minimum supported Rust version is 1.36.
31+
version is released. Currently, the minimum supported Rust version is 1.38.
3232

3333
## License
3434

crossbeam-deque/src/deque.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<T> Buffer<T> {
6464
/// that would be more expensive and difficult to implement generically for all types `T`.
6565
/// Hence, as a hack, we use a volatile write instead.
6666
unsafe fn write(&self, index: isize, task: MaybeUninit<T>) {
67-
ptr::write_volatile(self.at(index) as *mut MaybeUninit<T>, task)
67+
ptr::write_volatile(self.at(index).cast::<MaybeUninit<T>>(), task)
6868
}
6969

7070
/// Reads a task from the specified `index`.
@@ -74,7 +74,7 @@ impl<T> Buffer<T> {
7474
/// that would be more expensive and difficult to implement generically for all types `T`.
7575
/// Hence, as a hack, we use a volatile load instead.
7676
unsafe fn read(&self, index: isize) -> MaybeUninit<T> {
77-
ptr::read_volatile(self.at(index) as *mut MaybeUninit<T>)
77+
ptr::read_volatile(self.at(index).cast::<MaybeUninit<T>>())
7878
}
7979
}
8080

@@ -1119,6 +1119,11 @@ struct Slot<T> {
11191119
}
11201120

11211121
impl<T> Slot<T> {
1122+
const UNINIT: Self = Self {
1123+
task: UnsafeCell::new(MaybeUninit::uninit()),
1124+
state: AtomicUsize::new(0),
1125+
};
1126+
11221127
/// Waits until a task is written into the slot.
11231128
fn wait_write(&self) {
11241129
let backoff = Backoff::new();
@@ -1142,13 +1147,10 @@ struct Block<T> {
11421147
impl<T> Block<T> {
11431148
/// Creates an empty block that starts at `start_index`.
11441149
fn new() -> Block<T> {
1145-
// SAFETY: This is safe because:
1146-
// [1] `Block::next` (AtomicPtr) may be safely zero initialized.
1147-
// [2] `Block::slots` (Array) may be safely zero initialized because of [3, 4].
1148-
// [3] `Slot::task` (UnsafeCell) may be safely zero initialized because it
1149-
// holds a MaybeUninit.
1150-
// [4] `Slot::state` (AtomicUsize) may be safely zero initialized.
1151-
unsafe { MaybeUninit::zeroed().assume_init() }
1150+
Self {
1151+
next: AtomicPtr::new(ptr::null_mut()),
1152+
slots: [Slot::UNINIT; BLOCK_CAP],
1153+
}
11521154
}
11531155

11541156
/// Waits until the next pointer is set.

crossbeam-epoch/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name = "crossbeam-epoch"
66
# - Create "crossbeam-epoch-X.Y.Z" git tag
77
version = "0.9.9"
88
edition = "2018"
9-
rust-version = "1.36"
9+
rust-version = "1.38"
1010
license = "MIT OR Apache-2.0"
1111
repository = "https://github.com/crossbeam-rs/crossbeam"
1212
homepage = "https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-epoch"

crossbeam-epoch/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-epoch#license)
88
https://crates.io/crates/crossbeam-epoch)
99
[![Documentation](https://docs.rs/crossbeam-epoch/badge.svg)](
1010
https://docs.rs/crossbeam-epoch)
11-
[![Rust 1.36+](https://img.shields.io/badge/rust-1.36+-lightgray.svg)](
11+
[![Rust 1.38+](https://img.shields.io/badge/rust-1.38+-lightgray.svg)](
1212
https://www.rust-lang.org)
1313
[![chat](https://img.shields.io/discord/569610676205781012.svg?logo=discord)](https://discord.com/invite/JXYwgWZ)
1414

@@ -35,7 +35,7 @@ crossbeam-epoch = "0.9"
3535

3636
Crossbeam Epoch supports stable Rust releases going back at least six months,
3737
and every time the minimum supported Rust version is increased, a new minor
38-
version is released. Currently, the minimum supported Rust version is 1.36.
38+
version is released. Currently, the minimum supported Rust version is 1.38.
3939

4040
## License
4141

crossbeam-epoch/src/atomic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl<T> Pointable for [MaybeUninit<T>] {
252252
let size = mem::size_of::<Array<T>>() + mem::size_of::<MaybeUninit<T>>() * len;
253253
let align = mem::align_of::<Array<T>>();
254254
let layout = alloc::Layout::from_size_align(size, align).unwrap();
255-
let ptr = alloc::alloc(layout) as *mut Array<T>;
255+
let ptr = alloc::alloc(layout).cast::<Array<T>>();
256256
if ptr.is_null() {
257257
alloc::handle_alloc_error(layout);
258258
}

crossbeam-epoch/src/deferred.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ impl fmt::Debug for Deferred {
2929
}
3030

3131
impl Deferred {
32+
pub(crate) const NO_OP: Self = {
33+
fn no_op_call(_raw: *mut u8) {}
34+
Self {
35+
call: no_op_call,
36+
data: MaybeUninit::uninit(),
37+
_marker: PhantomData,
38+
}
39+
};
40+
3241
/// Constructs a new `Deferred` from a `FnOnce()`.
3342
pub(crate) fn new<F: FnOnce()>(f: F) -> Self {
3443
let size = mem::size_of::<F>();
@@ -37,10 +46,10 @@ impl Deferred {
3746
unsafe {
3847
if size <= mem::size_of::<Data>() && align <= mem::align_of::<Data>() {
3948
let mut data = MaybeUninit::<Data>::uninit();
40-
ptr::write(data.as_mut_ptr() as *mut F, f);
49+
ptr::write(data.as_mut_ptr().cast::<F>(), f);
4150

4251
unsafe fn call<F: FnOnce()>(raw: *mut u8) {
43-
let f: F = ptr::read(raw as *mut F);
52+
let f: F = ptr::read(raw.cast::<F>());
4453
f();
4554
}
4655

@@ -52,12 +61,12 @@ impl Deferred {
5261
} else {
5362
let b: Box<F> = Box::new(f);
5463
let mut data = MaybeUninit::<Data>::uninit();
55-
ptr::write(data.as_mut_ptr() as *mut Box<F>, b);
64+
ptr::write(data.as_mut_ptr().cast::<Box<F>>(), b);
5665

5766
unsafe fn call<F: FnOnce()>(raw: *mut u8) {
5867
// It's safe to cast `raw` from `*mut u8` to `*mut Box<F>`, because `raw` is
5968
// originally derived from `*mut Box<F>`.
60-
let b: Box<F> = ptr::read(raw as *mut Box<F>);
69+
let b: Box<F> = ptr::read(raw.cast::<Box<F>>());
6170
(*b)();
6271
}
6372

@@ -74,7 +83,7 @@ impl Deferred {
7483
#[inline]
7584
pub(crate) fn call(mut self) {
7685
let call = self.call;
77-
unsafe { call(self.data.as_mut_ptr() as *mut u8) };
86+
unsafe { call(self.data.as_mut_ptr().cast::<u8>()) };
7887
}
7988
}
8089

0 commit comments

Comments
 (0)