Unsafe is no longer necessary as of rustc 1.34 #488

Closed
opened 2020-08-20 20:06:52 -05:00 by Gaelan · 2 comments
Gaelan commented 2020-08-20 20:06:52 -05:00 (Migrated from github.com)

This code (and another identical line in the same file) uses unsafe to convert a &[u8] to a &[u8; 8]: github.com/uuid-rs/uuid@f177d20151/src/lib.rs (L360)

From Rust 1.34 and on (before that, TryFrom wasn't stable), the following code compiles to the exact same assembly as the code above:

self.as_bytes()[8..16].try_into().unwrap()

Tested with rustc 1.34 and 1.45.2 on godbolt.org, with -O.

The try_into version is simpler and doesn't use unsafe, so it'd probably be a good idea to switch to that once support for Rust 1.32/33 is dropped.

This code (and another identical line in the same file) uses unsafe to convert a `&[u8]` to a `&[u8; 8]`: https://github.com/uuid-rs/uuid/blob/f177d20151f23a8beb9a75df40c736b27dead0d1/src/lib.rs#L360 From Rust 1.34 and on (before that, TryFrom wasn't stable), the following code compiles to the exact same assembly as the code above: ```rust self.as_bytes()[8..16].try_into().unwrap() ``` Tested with rustc 1.34 and 1.45.2 on godbolt.org, with `-O`. The `try_into` version is simpler and doesn't use unsafe, so it'd probably be a good idea to switch to that once support for Rust 1.32/33 is dropped.
kinggoesgaming commented 2020-08-28 01:05:29 -05:00 (Migrated from github.com)

Our current MSRV is 1.32.0 😞

However I will keep the issue open so we can update the relevant code when we get to it

Our current MSRV is 1.32.0 😞 However I will keep the issue open so we can update the relevant code when we get to it
KodrAus commented 2020-12-21 01:24:40 -06:00 (Migrated from github.com)

We've just bumped our MSRV to 1.34.0 in #501 with an update to getrandom.

Would anybody like to submit a PR for this?

We've just bumped our MSRV to `1.34.0` in #501 with an update to `getrandom`. Would anybody like to submit a PR for this?
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-uuid-rs/uuid#488
No description provided.