New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rand: Fix most clippy warnings #840
Changes from all commits
dcfd356
c2202a9
3808dd2
74484bf
fef8f78
d74c603
4af5671
805d946
ce583e0
047fc24
8f8f836
553088f
60107eb
6947154
78c470e
1c516eb
183fadb
80f3571
b92db7c
1b40a2b
13fa09c
bab3a37
a983df4
4607c32
6d79ebd
1510b6c
cf1b67c
2d4a6ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,6 +188,7 @@ where <R as BlockRngCore>::Results: AsRef<[u32]> + AsMut<[u32]> | |
let read_u64 = |results: &[u32], index| { | ||
if cfg!(any(target_endian = "little")) { | ||
// requires little-endian CPU | ||
#[allow(clippy::cast_ptr_alignment)] // false positive | ||
let ptr: *const u64 = results[index..=index+1].as_ptr() as *const u64; | ||
unsafe { ptr::read_unaligned(ptr) } | ||
} else { | ||
|
@@ -233,7 +234,8 @@ where <R as BlockRngCore>::Results: AsRef<[u32]> + AsMut<[u32]> | |
|
||
#[inline(always)] | ||
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { | ||
Ok(self.fill_bytes(dest)) | ||
self.fill_bytes(dest); | ||
Ok(()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is to appease a lint intended to catch accidental semicolons, so arguably a false positive. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I revert this? I think the new version is slightly more clear, but I don't have a strong preference. |
||
} | ||
} | ||
|
||
|
@@ -408,7 +410,8 @@ where <R as BlockRngCore>::Results: AsRef<[u64]> + AsMut<[u64]> | |
|
||
#[inline(always)] | ||
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { | ||
Ok(self.fill_bytes(dest)) | ||
self.fill_bytes(dest); | ||
Ok(()) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
results
is aligned to 32bits, but then 64bits are read. I don't understand why this would be a false positive.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rust-lang/rust-clippy#2881
Guess what we do with the result:
ptr::read_unaligned(ptr)