Skip to content

Commit 71a5abb

Browse files
committed
Implement various Clippy suggestions
Many lints were disabled due to low or nil utility, and a few suggestions ignored in the interests of readability or correctness. Command: ~/.cargo/bin/cargo-clippy --features=log,nightly,serde-1 -- -A inline_always -A approx_constant -A unreadable_literal -A cast_lossless -A len_zero -A unit_arg -A many_single_char_names -A doc_markdown -A single_match -A transmute_int_to_float -A float_cmp -A identity_op -A too_many_arguments -A new_ret_no_self
1 parent 983f4e4 commit 71a5abb

File tree

20 files changed

+53
-49
lines changed

20 files changed

+53
-49
lines changed

benches/distributions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ macro_rules! distr_float {
4343
let mut accum = 0.0;
4444
for _ in 0..::RAND_BENCH_N {
4545
let x: $ty = distr.sample(&mut rng);
46-
accum = accum + x;
46+
accum += x;
4747
}
4848
black_box(accum);
4949
});

examples/monty-hall.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn simulate<R: Rng>(random_door: &Range<RangeInt<u32>>, rng: &mut R)
5858
choice = switch_door(choice, open);
5959
}
6060

61-
SimulationResult { win: choice == car, switch: switch }
61+
SimulationResult { win: choice == car, switch }
6262
}
6363

6464
// Returns the door the game host opens given our choice and knowledge of

src/distributions/binomial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Binomial {
4141
pub fn new(n: u64, p: f64) -> Binomial {
4242
assert!(p > 0.0, "Binomial::new called with p <= 0");
4343
assert!(p < 1.0, "Binomial::new called with p >= 1");
44-
Binomial { n: n, p: p }
44+
Binomial { n, p }
4545
}
4646
}
4747

src/distributions/float.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub(crate) trait IntoFloat {
2525
/// The resulting value will fall in a range that depends on the exponent.
2626
/// As an example the range with exponent 0 will be
2727
/// [2<sup>0</sup>..2<sup>1</sup>), which is [1..2).
28-
#[inline(always)]
2928
fn into_float_with_exponent(self, exponent: i32) -> Self::F;
3029
}
3130

src/distributions/gamma.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl Gamma {
109109
} else {
110110
Large(GammaLargeShape::new_raw(shape, scale))
111111
};
112-
Gamma { repr: repr }
112+
Gamma { repr }
113113
}
114114
}
115115

@@ -126,9 +126,9 @@ impl GammaLargeShape {
126126
fn new_raw(shape: f64, scale: f64) -> GammaLargeShape {
127127
let d = shape - 1. / 3.;
128128
GammaLargeShape {
129-
scale: scale,
129+
scale,
130130
c: 1. / (9. * d).sqrt(),
131-
d: d
131+
d
132132
}
133133
}
134134
}
@@ -211,7 +211,7 @@ impl ChiSquared {
211211
assert!(k > 0.0, "ChiSquared::new called with `k` < 0");
212212
DoFAnythingElse(Gamma::new(0.5 * k, 2.0))
213213
};
214-
ChiSquared { repr: repr }
214+
ChiSquared { repr }
215215
}
216216
}
217217
impl Distribution<f64> for ChiSquared {

src/distributions/log_gamma.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ pub fn log_gamma(x: f64) -> f64 {
3939
// the first few terms of the series for Ag(x)
4040
let mut a = 1.000000000190015;
4141
let mut denom = x;
42-
for j in 0..6 {
42+
for coeff in &coefficients {
4343
denom += 1.0;
44-
a += coefficients[j] / denom;
44+
a += coeff / denom;
4545
}
4646

4747
// get everything together
4848
// a is Ag(x)
4949
// 2.5066... is sqrt(2pi)
50-
return log + (2.5066282746310005 * a / x).ln();
50+
log + (2.5066282746310005 * a / x).ln()
5151
}

src/distributions/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl<'a, T: Clone> WeightedChoice<'a, T> {
273273
assert!(running_total != 0, "WeightedChoice::new called with a total weight of 0");
274274

275275
WeightedChoice {
276-
items: items,
276+
items,
277277
// we're likely to be generating numbers in this range
278278
// relatively often, so might as well cache it
279279
weight_range: Range::new(0, running_total)
@@ -320,7 +320,7 @@ impl<'a, T: Clone> Distribution<T> for WeightedChoice<'a, T> {
320320
}
321321
modifier /= 2;
322322
}
323-
return self.items[idx + 1].item.clone();
323+
self.items[idx + 1].item.clone()
324324
}
325325
}
326326

src/distributions/normal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ impl Normal {
104104
pub fn new(mean: f64, std_dev: f64) -> Normal {
105105
assert!(std_dev >= 0.0, "Normal::new called with `std_dev` < 0");
106106
Normal {
107-
mean: mean,
108-
std_dev: std_dev
107+
mean,
108+
std_dev
109109
}
110110
}
111111
}

src/distributions/other.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl Distribution<char> for Uniform {
5858
impl Distribution<char> for Alphanumeric {
5959
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> char {
6060
const RANGE: u32 = 26 + 26 + 10;
61-
const GEN_ASCII_STR_CHARSET: &'static [u8] =
61+
const GEN_ASCII_STR_CHARSET: &[u8] =
6262
b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\
6363
abcdefghijklmnopqrstuvwxyz\
6464
0123456789";

src/distributions/poisson.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ impl Poisson {
4646
assert!(lambda > 0.0, "Poisson::new called with lambda <= 0");
4747
let log_lambda = lambda.ln();
4848
Poisson {
49-
lambda: lambda,
49+
lambda,
5050
exp_lambda: (-lambda).exp(),
51-
log_lambda: log_lambda,
51+
log_lambda,
5252
sqrt_2lambda: (2.0 * lambda).sqrt(),
5353
magic_val: lambda * log_lambda - log_gamma(1.0 + lambda),
5454
}

0 commit comments

Comments
 (0)