Skip to content

Commit e1d4e74

Browse files
committed
ci.yml: fix ci, fix clippy lint
1 parent ae18cb9 commit e1d4e74

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,28 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v2
13+
1314
- uses: actions-rs/toolchain@88dc2356392166efad76775c878094f4e83ff746
1415
with:
1516
profile: minimal
1617
toolchain: "1.60" # MSRV
1718
override: true
19+
components: rustfmt, clippy
1820

1921
- name: Tests
2022
uses: actions-rs/cargo@9e120dd99b0fbad1c065f686657e914e76bd7b72
2123
with:
2224
command: test # Test debug assertions; we don't test with `--release` because it enables a lot more CPU-heavy tests.
2325

24-
- run: rustup component add rustfmt
2526
- name: Rustfmt
27+
if: success() || failure()
2628
uses: actions-rs/cargo@9e120dd99b0fbad1c065f686657e914e76bd7b72
2729
with:
2830
command: fmt
2931
args: --all -- --check
3032

31-
- run: rustup component add clippy
3233
- name: Clippy
34+
if: success() || failure()
3335
uses: actions-rs/cargo@9e120dd99b0fbad1c065f686657e914e76bd7b72
3436
with:
3537
command: clippy

src/lib.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,7 @@ pub fn generate_salt(website: &str, username: &str, counter: u32) -> std::vec::V
195195

196196
// SAFETY: `uninit_output` was fully initialized in
197197
// `generate_salt_to_uninit`.
198-
unsafe {
199-
std::mem::transmute::<std::vec::Vec<MaybeUninit<u8>>, std::vec::Vec<u8>>(uninit_output)
200-
}
198+
unsafe { assume_init_vec(uninit_output) }
201199
}
202200

203201
/// The minimum length of the entropy in bytes, inclusive.
@@ -367,9 +365,7 @@ pub fn render_password(entropy: &[u8], charset: CharacterSet, len: usize) -> std
367365

368366
// SAFETY: `uninit_output` was fully initialized in
369367
// `render_password_to_uninit`.
370-
let output = unsafe {
371-
std::mem::transmute::<std::vec::Vec<MaybeUninit<u8>>, std::vec::Vec<u8>>(uninit_output)
372-
};
368+
let output = unsafe { assume_init_vec(uninit_output) };
373369

374370
// SAFETY: characters are all extracted from `charset`, which only contains
375371
// a limited set of ASCII characters.
@@ -430,6 +426,15 @@ fn uninit_vec<T>(len: usize) -> std::vec::Vec<MaybeUninit<T>> {
430426
.collect()
431427
}
432428

429+
#[cfg(feature = "std")]
430+
#[inline(always)]
431+
unsafe fn assume_init_vec(mut vec: std::vec::Vec<MaybeUninit<u8>>) -> std::vec::Vec<u8> {
432+
let (ptr, length, capacity) = (vec.as_mut_ptr(), vec.len(), vec.capacity());
433+
434+
std::mem::forget(vec);
435+
std::vec::Vec::from_raw_parts(ptr.cast(), length, capacity)
436+
}
437+
433438
#[cfg(test)]
434439
mod fingerprint_tests {
435440
use super::*;

0 commit comments

Comments
 (0)