Skip to content

Commit 8292d10

Browse files
authored
Merge pull request #36 from artichoke/fixups
Add lints and ensure doctests wrapped in functions are run
2 parents 96bc8de + 0c9db66 commit 8292d10

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#![deny(missing_docs, intra_doc_link_resolution_failure)]
1616
#![deny(missing_debug_implementations)]
1717
#![warn(rust_2018_idioms)]
18+
#![warn(trivial_casts, trivial_numeric_casts)]
19+
#![warn(unused_qualifications)]
20+
#![warn(variant_size_differences)]
1821
#![forbid(unsafe_code)]
1922
#![cfg_attr(not(feature = "std"), no_std)]
2023

@@ -47,14 +50,15 @@
4750
//! ```
4851
//! # use rand_core::{RngCore, SeedableRng};
4952
//! # use rand_mt::Mt64;
50-
//! # fn main() -> Result<(), rand_core::Error> {
53+
//! # fn example() -> Result<(), rand_core::Error> {
5154
//! // Create the RNG.
5255
//! let mut rng = Mt64::new(0x1234_567_89ab_cdef_u64);
5356
//! // start grabbing randomness from rng...
5457
//! let mut buf = vec![0; 512];
5558
//! rng.try_fill_bytes(&mut buf)?;
5659
//! # Ok(())
5760
//! # }
61+
//! # example().unwrap()
5862
//! ```
5963
//!
6064
//! Or if you want to use the default (fixed) seeds that are specified in the

src/mt.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// option. All files in the project carrying such notice may not be copied,
1010
// modified, or distributed except according to those terms.
1111

12-
use core::cmp;
12+
use core::cmp::Ordering;
1313
use core::convert::TryFrom;
1414
use core::fmt;
1515
use core::hash;
@@ -54,25 +54,25 @@ pub struct Mt19937GenRand32 {
5454
state: [Wrapping<u32>; N],
5555
}
5656

57-
impl cmp::Eq for Mt19937GenRand32 {}
57+
impl Eq for Mt19937GenRand32 {}
5858

59-
impl cmp::PartialEq for Mt19937GenRand32 {
59+
impl PartialEq for Mt19937GenRand32 {
6060
fn eq(&self, other: &Self) -> bool {
6161
self.state[..] == other.state[..] && self.idx == other.idx
6262
}
6363
}
6464

65-
impl cmp::Ord for Mt19937GenRand32 {
66-
fn cmp(&self, other: &Self) -> cmp::Ordering {
65+
impl Ord for Mt19937GenRand32 {
66+
fn cmp(&self, other: &Self) -> Ordering {
6767
match self.state[..].cmp(&other.state[..]) {
68-
cmp::Ordering::Equal => self.idx.cmp(&other.idx),
68+
Ordering::Equal => self.idx.cmp(&other.idx),
6969
ordering => ordering,
7070
}
7171
}
7272
}
7373

74-
impl cmp::PartialOrd for Mt19937GenRand32 {
75-
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
74+
impl PartialOrd for Mt19937GenRand32 {
75+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
7676
Some(self.cmp(other))
7777
}
7878
}
@@ -220,7 +220,7 @@ impl RngCore for Mt19937GenRand32 {
220220
/// ```
221221
/// # use rand_core::RngCore;
222222
/// # use rand_mt::Mt19937GenRand32;
223-
/// # fn main() -> Result<(), rand_core::Error> {
223+
/// # fn example() -> Result<(), rand_core::Error> {
224224
/// let mut mt = Mt19937GenRand32::new_unseeded();
225225
/// let mut buf = [0; 32];
226226
/// mt.try_fill_bytes(&mut buf)?;
@@ -230,6 +230,7 @@ impl RngCore for Mt19937GenRand32 {
230230
/// assert_ne!([0; 31], buf);
231231
/// # Ok(())
232232
/// # }
233+
/// # example().unwrap()
233234
/// ```
234235
#[inline]
235236
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> {

src/mt64.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// option. All files in the project carrying such notice may not be copied,
1010
// modified, or distributed except according to those terms.
1111

12-
use core::cmp;
12+
use core::cmp::Ordering;
1313
use core::convert::TryFrom;
1414
use core::fmt;
1515
use core::hash;
@@ -51,25 +51,25 @@ pub struct Mt19937GenRand64 {
5151
state: [Wrapping<u64>; NN],
5252
}
5353

54-
impl cmp::Eq for Mt19937GenRand64 {}
54+
impl Eq for Mt19937GenRand64 {}
5555

56-
impl cmp::PartialEq for Mt19937GenRand64 {
56+
impl PartialEq for Mt19937GenRand64 {
5757
fn eq(&self, other: &Self) -> bool {
5858
self.state[..] == other.state[..] && self.idx == other.idx
5959
}
6060
}
6161

62-
impl cmp::Ord for Mt19937GenRand64 {
63-
fn cmp(&self, other: &Self) -> cmp::Ordering {
62+
impl Ord for Mt19937GenRand64 {
63+
fn cmp(&self, other: &Self) -> Ordering {
6464
match self.state[..].cmp(&other.state[..]) {
65-
cmp::Ordering::Equal => self.idx.cmp(&other.idx),
65+
Ordering::Equal => self.idx.cmp(&other.idx),
6666
ordering => ordering,
6767
}
6868
}
6969
}
7070

71-
impl cmp::PartialOrd for Mt19937GenRand64 {
72-
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
71+
impl PartialOrd for Mt19937GenRand64 {
72+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
7373
Some(self.cmp(other))
7474
}
7575
}
@@ -216,7 +216,7 @@ impl RngCore for Mt19937GenRand64 {
216216
/// ```
217217
/// # use rand_core::RngCore;
218218
/// # use rand_mt::Mt19937GenRand64;
219-
/// # fn main() -> Result<(), rand_core::Error> {
219+
/// # fn example() -> Result<(), rand_core::Error> {
220220
/// let mut mt = Mt19937GenRand64::new_unseeded();
221221
/// let mut buf = [0; 32];
222222
/// mt.try_fill_bytes(&mut buf)?;
@@ -226,6 +226,7 @@ impl RngCore for Mt19937GenRand64 {
226226
/// assert_ne!([0; 31], buf);
227227
/// # Ok(())
228228
/// # }
229+
/// # example().unwrap()
229230
/// ```
230231
#[inline]
231232
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core::Error> {

0 commit comments

Comments
 (0)