Skip to content

Commit 1788f44

Browse files
authored
Upgrade some code for MSRV 1.65 (#1885)
Now that our MSRV is 1.65, we can clean up some code. Makes progress on #67
1 parent 2b56c07 commit 1788f44

File tree

5 files changed

+6
-49
lines changed

5 files changed

+6
-49
lines changed

src/layout.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,8 @@ impl DstLayout {
474474
// invalid type) instead of allowing this panic to be hidden if the cast
475475
// would have failed anyway for runtime reasons (such as a too-small
476476
// memory region).
477-
//
478-
// TODO(#67): Once our MSRV is 1.65, use let-else:
479-
// https://blog.rust-lang.org/2022/11/03/Rust-1.65.0.html#let-else-statements
480-
let size_info = match self.size_info.try_to_nonzero_elem_size() {
481-
Some(size_info) => size_info,
482-
None => panic!("attempted to cast to slice type with zero-sized element"),
477+
let Some(size_info) = self.size_info.try_to_nonzero_elem_size() else {
478+
panic!("attempted to cast to slice type with zero-sized element");
483479
};
484480

485481
// Precondition
@@ -531,13 +527,9 @@ impl DstLayout {
531527
util::round_down_to_next_multiple_of_alignment(bytes_len, self.align);
532528
// Calculate the maximum number of bytes that could be consumed
533529
// by the trailing slice.
534-
//
535-
// TODO(#67): Once our MSRV is 1.65, use let-else:
536-
// https://blog.rust-lang.org/2022/11/03/Rust-1.65.0.html#let-else-statements
537-
let max_slice_and_padding_bytes = match max_total_bytes.checked_sub(offset) {
538-
Some(max) => max,
530+
let Some(max_slice_and_padding_bytes) = max_total_bytes.checked_sub(offset) else {
539531
// `bytes_len` too small even for 0 trailing slice elements.
540-
None => return Err(MetadataCastError::Size),
532+
return Err(MetadataCastError::Size);
541533
};
542534

543535
// Calculate the number of elements that fit in
@@ -596,11 +588,6 @@ impl DstLayout {
596588
}
597589
}
598590

599-
// TODO(#67): For some reason, on our MSRV toolchain, this `allow` isn't
600-
// enforced despite having `#![allow(unknown_lints)]` at the crate root, but
601-
// putting it here works. Once our MSRV is high enough that this bug has been
602-
// fixed, remove this `allow`.
603-
#[allow(unknown_lints)]
604591
#[cfg(test)]
605592
mod tests {
606593
use super::*;

src/pointer/ptr.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,9 +1296,6 @@ mod _casts {
12961296
U: 'a + ?Sized + KnownLayout + AliasingSafe<[u8], I::Aliasing, R>,
12971297
R: AliasingSafeReason,
12981298
{
1299-
// TODO(#67): Remove this allow. See NonNulSlicelExt for more
1300-
// details.
1301-
#[allow(unstable_name_collisions)]
13021299
match self.try_cast_into(CastType::Prefix, meta) {
13031300
Ok((slf, remainder)) => {
13041301
if remainder.len() == 0 {

src/util/macro_util.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,7 @@ pub const unsafe fn transmute_ref<'dst, 'src: 'dst, Src: 'src, Dst: 'dst>(
469469
// - The caller has guaranteed that alignment is not increased.
470470
// - We know that the returned lifetime will not outlive the input lifetime
471471
// thanks to the lifetime bounds on this function.
472-
//
473-
// TODO(#67): Once our MSRV is 1.58, replace this `transmute` with `&*dst`.
474-
#[allow(clippy::transmute_ptr_to_ref)]
475-
unsafe {
476-
mem::transmute(dst)
477-
}
472+
unsafe { &*dst }
478473
}
479474

480475
/// Transmutes a mutable reference of one type to a mutable reference of another

src/util/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ pub(crate) mod polyfills {
725725
// toolchain versions, `ptr.slice_from_raw_parts()` resolves to the inherent
726726
// method rather than to this trait, and so this trait is considered unused.
727727
//
728-
// TODO(#67): Once our MSRV is high enough, remove this.
728+
// TODO(#67): Once our MSRV is >= 1.79, remove this.
729729
#[allow(unused)]
730730
pub(crate) trait NumExt {
731731
/// Subtract without checking for underflow.

zerocopy-derive/src/lib.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,25 +1349,3 @@ fn impl_block<D: DataExt>(
13491349
}
13501350
}
13511351
}
1352-
1353-
// A polyfill for `Option::then_some`, which was added after our MSRV.
1354-
//
1355-
// The `#[allow(unused)]` is necessary because, on sufficiently recent toolchain
1356-
// versions, `b.then_some(...)` resolves to the inherent method rather than to
1357-
// this trait, and so this trait is considered unused.
1358-
//
1359-
// TODO(#67): Remove this once our MSRV is >= 1.62.
1360-
#[allow(unused)]
1361-
trait BoolExt {
1362-
fn then_some<T>(self, t: T) -> Option<T>;
1363-
}
1364-
1365-
impl BoolExt for bool {
1366-
fn then_some<T>(self, t: T) -> Option<T> {
1367-
if self {
1368-
Some(t)
1369-
} else {
1370-
None
1371-
}
1372-
}
1373-
}

0 commit comments

Comments
 (0)