Skip to content
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

Fix most clippy lints #1007

Merged
merged 3 commits into from Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/distributions/weighted_index.rs
Expand Up @@ -161,7 +161,7 @@ impl<X: SampleUniform + PartialOrd> WeightedIndex<X> {
if *w < zero {
return Err(WeightedError::InvalidWeight);
}
if i >= self.cumulative_weights.len() + 1 {
if i > self.cumulative_weights.len() {
return Err(WeightedError::TooMany);
}

Expand Down
5 changes: 2 additions & 3 deletions src/rngs/mock.rs
Expand Up @@ -72,13 +72,12 @@ impl RngCore for StepRng {

#[cfg(test)]
mod tests {
use super::*;

#[test]
#[cfg(feature = "serde1")]
fn test_serialization_step_rng() {
let some_rng = StepRng::new(42, 7);
let de_some_rng: StepRng = bincode::deserialize(&bincode::serialize(&some_rng).unwrap()).unwrap();
let de_some_rng: StepRng =
bincode::deserialize(&bincode::serialize(&some_rng).unwrap()).unwrap();
assert_eq!(some_rng.v, de_some_rng.v);
assert_eq!(some_rng.a, de_some_rng.a);

Expand Down
7 changes: 6 additions & 1 deletion src/seq/index.rs
Expand Up @@ -85,10 +85,15 @@ impl IndexVec {
IndexVec::USize(ref v) => IndexVecIter::USize(v.iter()),
}
}
}

impl IntoIterator for IndexVec {
type Item = usize;
type IntoIter = IndexVecIntoIter;

/// Convert into an iterator over the indices as a sequence of `usize` values
#[inline]
pub fn into_iter(self) -> IndexVecIntoIter {
fn into_iter(self) -> IndexVecIntoIter {
match self {
IndexVec::U32(v) => IndexVecIntoIter::U32(v.into_iter()),
IndexVec::USize(v) => IndexVecIntoIter::USize(v.into_iter()),
Expand Down
22 changes: 9 additions & 13 deletions src/seq/mod.rs
Expand Up @@ -44,13 +44,11 @@ use crate::Rng;
/// ```
/// use rand::seq::SliceRandom;
///
/// fn main() {
/// let mut rng = rand::thread_rng();
/// let mut bytes = "Hello, random!".to_string().into_bytes();
/// bytes.shuffle(&mut rng);
/// let str = String::from_utf8(bytes).unwrap();
/// println!("{}", str);
/// }
/// let mut rng = rand::thread_rng();
/// let mut bytes = "Hello, random!".to_string().into_bytes();
/// bytes.shuffle(&mut rng);
/// let str = String::from_utf8(bytes).unwrap();
/// println!("{}", str);
/// ```
/// Example output (non-deterministic):
/// ```none
Expand Down Expand Up @@ -228,12 +226,10 @@ pub trait SliceRandom {
/// ```
/// use rand::seq::IteratorRandom;
///
/// fn main() {
/// let mut rng = rand::thread_rng();
///
/// let faces = "😀😎😐😕😠😢";
/// println!("I am {}!", faces.chars().choose(&mut rng).unwrap());
/// }
/// let mut rng = rand::thread_rng();
///
/// let faces = "😀😎😐😕😠😢";
/// println!("I am {}!", faces.chars().choose(&mut rng).unwrap());
/// ```
/// Example output (non-deterministic):
/// ```none
Expand Down