Skip to content

Commit faa320e

Browse files
committed
Apply clippy suggestions for rand_core
1 parent 9901e39 commit faa320e

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

rand_core/src/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ impl Error {
9999
/// Create a new instance, with specified kind and a message.
100100
pub fn new(kind: ErrorKind, msg: &'static str) -> Self {
101101
#[cfg(feature="std")] {
102-
Error { kind: kind, msg: msg, cause: None }
102+
Error { kind, msg, cause: None }
103103
}
104104
#[cfg(not(feature="std"))] {
105-
Error { kind: kind, msg: msg }
105+
Error { kind, msg }
106106
}
107107
}
108108

@@ -119,7 +119,7 @@ impl Error {
119119
pub fn with_cause<E>(kind: ErrorKind, msg: &'static str, cause: E) -> Self
120120
where E: Into<Box<stdError + Send + Sync>>
121121
{
122-
Error { kind: kind, msg: msg, cause: Some(cause.into()) }
122+
Error { kind, msg, cause: Some(cause.into()) }
123123
}
124124

125125
/// Create a new instance, with specified kind, message, and a
@@ -128,7 +128,7 @@ impl Error {
128128
/// In `no_std` mode the *cause* is ignored.
129129
#[cfg(not(feature="std"))]
130130
pub fn with_cause<E>(kind: ErrorKind, msg: &'static str, _cause: E) -> Self {
131-
Error { kind: kind, msg: msg }
131+
Error { kind, msg }
132132
}
133133

134134
/// Take the cause, if any. This allows the embedded cause to be extracted.

rand_core/src/impls.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ use {RngCore, BlockRngCore, CryptoRng, SeedableRng, Error};
3030
/// Implement `next_u64` via `next_u32`, little-endian order.
3131
pub fn next_u64_via_u32<R: RngCore + ?Sized>(rng: &mut R) -> u64 {
3232
// Use LE; we explicitly generate one value before the next.
33-
let x = rng.next_u32() as u64;
34-
let y = rng.next_u32() as u64;
33+
let x = u64::from(rng.next_u32());
34+
let y = u64::from(rng.next_u32());
3535
(y << 32) | x
3636
}
3737

@@ -223,8 +223,8 @@ where <R as BlockRngCore>::Results: AsRef<[u32]>
223223
// requires little-endian CPU supporting unaligned reads:
224224
unsafe { *(&results[index] as *const u32 as *const u64) }
225225
} else {
226-
let x = results[index] as u64;
227-
let y = results[index + 1] as u64;
226+
let x = u64::from(results[index]);
227+
let y = u64::from(results[index + 1]);
228228
(y << 32) | x
229229
}
230230
};
@@ -241,10 +241,10 @@ where <R as BlockRngCore>::Results: AsRef<[u32]>
241241
self.index = 2;
242242
read_u64(self.results.as_ref(), 0)
243243
} else {
244-
let x = self.results.as_ref()[len-1] as u64;
244+
let x = u64::from(self.results.as_ref()[len-1]);
245245
self.core.generate(&mut self.results);
246246
self.index = 1;
247-
let y = self.results.as_ref()[0] as u64;
247+
let y = u64::from(self.results.as_ref()[0]);
248248
(y << 32) | x
249249
}
250250
}
@@ -272,7 +272,8 @@ where <R as BlockRngCore>::Results: AsRef<[u32]>
272272

273273
while filled < end_direct {
274274
let dest_u32: &mut R::Results = unsafe {
275-
::core::mem::transmute(dest[filled..].as_mut_ptr())
275+
&mut *(dest[filled..].as_mut_ptr() as
276+
*mut <R as BlockRngCore>::Results)
276277
};
277278
self.core.generate(dest_u32);
278279
filled += self.results.as_ref().len() * 4;
@@ -282,7 +283,7 @@ where <R as BlockRngCore>::Results: AsRef<[u32]>
282283
if len_remainder > 0 {
283284
self.core.generate(&mut self.results);
284285
let (consumed_u32, _) =
285-
fill_via_u32_chunks(&mut self.results.as_ref(),
286+
fill_via_u32_chunks(self.results.as_ref(),
286287
&mut dest[filled..]);
287288

288289
self.index = consumed_u32;
@@ -307,7 +308,8 @@ where <R as BlockRngCore>::Results: AsRef<[u32]>
307308
}
308309

309310
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> {
310-
Ok(self.fill_bytes(dest))
311+
self.fill_bytes(dest);
312+
Ok(())
311313
}
312314
}
313315

0 commit comments

Comments
 (0)