rustfmt: libflate, libfmt_macros, libgetopts, libgraphviz, liblog, librand
This commit is contained in:
parent
0dfd875b6e
commit
5fb6531903
12 changed files with 502 additions and 477 deletions
|
@ -82,7 +82,7 @@ impl Drop for Bytes {
|
|||
}
|
||||
|
||||
#[link(name = "miniz", kind = "static")]
|
||||
extern {
|
||||
extern "C" {
|
||||
/// Raw miniz compression function.
|
||||
fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
|
||||
src_buf_len: size_t,
|
||||
|
|
|
@ -187,7 +187,7 @@ impl<'a> Parser<'a> {
|
|||
Parser {
|
||||
input: s,
|
||||
cur: s.char_indices().peekable(),
|
||||
errors: vec!(),
|
||||
errors: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -236,7 +236,7 @@ impl<'a> Parser<'a> {
|
|||
if c.is_whitespace() {
|
||||
self.cur.next();
|
||||
} else {
|
||||
break
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -274,9 +274,7 @@ impl<'a> Parser<'a> {
|
|||
ArgumentIs(i)
|
||||
} else {
|
||||
match self.cur.peek() {
|
||||
Some(&(_, c)) if c.is_alphabetic() => {
|
||||
ArgumentNamed(self.word())
|
||||
}
|
||||
Some(&(_, c)) if c.is_alphabetic() => ArgumentNamed(self.word()),
|
||||
_ => ArgumentNext,
|
||||
}
|
||||
}
|
||||
|
@ -294,7 +292,7 @@ impl<'a> Parser<'a> {
|
|||
ty: &self.input[..0],
|
||||
};
|
||||
if !self.consume(':') {
|
||||
return spec
|
||||
return spec;
|
||||
}
|
||||
|
||||
// fill character
|
||||
|
@ -419,7 +417,7 @@ impl<'a> Parser<'a> {
|
|||
found = true;
|
||||
self.cur.next();
|
||||
} else {
|
||||
break
|
||||
break;
|
||||
}
|
||||
}
|
||||
if found {
|
||||
|
@ -447,7 +445,7 @@ mod tests {
|
|||
precision: CountImplied,
|
||||
width: CountImplied,
|
||||
ty: "",
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn musterr(s: &str) {
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -416,10 +416,10 @@ impl<'a> Id<'a> {
|
|||
_ => return Err(()),
|
||||
}
|
||||
if !chars.all(is_constituent) {
|
||||
return Err(())
|
||||
return Err(());
|
||||
}
|
||||
}
|
||||
return Ok(Id{ name: name });
|
||||
return Ok(Id { name: name });
|
||||
|
||||
fn is_letter_or_underscore(c: char) -> bool {
|
||||
in_range('a', c, 'z') || in_range('A', c, 'Z') || c == '_'
|
||||
|
@ -496,8 +496,7 @@ pub trait Labeller<'a,N,E> {
|
|||
/// Escape tags in such a way that it is suitable for inclusion in a
|
||||
/// Graphviz HTML label.
|
||||
pub fn escape_html(s: &str) -> String {
|
||||
s
|
||||
.replace("&", "&")
|
||||
s.replace("&", "&")
|
||||
.replace("\"", """)
|
||||
.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
|
@ -523,9 +522,11 @@ impl<'a> LabelText<'a> {
|
|||
// not escaping \\, since Graphviz escString needs to
|
||||
// interpret backslashes; see EscStr above.
|
||||
'\\' => f(c),
|
||||
_ => for c in c.escape_default() {
|
||||
_ => {
|
||||
for c in c.escape_default() {
|
||||
f(c)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fn escape_str(s: &str) -> String {
|
||||
|
@ -553,11 +554,13 @@ impl<'a> LabelText<'a> {
|
|||
fn pre_escaped_content(self) -> Cow<'a, str> {
|
||||
match self {
|
||||
EscStr(s) => s,
|
||||
LabelStr(s) => if s.contains('\\') {
|
||||
LabelStr(s) => {
|
||||
if s.contains('\\') {
|
||||
(&*s).escape_default().into_cow()
|
||||
} else {
|
||||
s
|
||||
},
|
||||
}
|
||||
}
|
||||
HtmlStr(s) => s,
|
||||
}
|
||||
}
|
||||
|
@ -738,7 +741,12 @@ mod tests {
|
|||
}
|
||||
|
||||
fn edge(from: usize, to: usize, label: &'static str, style: Style) -> Edge {
|
||||
Edge { from: from, to: to, label: label, style: style }
|
||||
Edge {
|
||||
from: from,
|
||||
to: to,
|
||||
label: label,
|
||||
style: style,
|
||||
}
|
||||
}
|
||||
|
||||
struct LabelledGraph {
|
||||
|
@ -1009,7 +1017,7 @@ r#"digraph single_cyclic_node {
|
|||
|
||||
#[test]
|
||||
fn hasse_diagram() {
|
||||
let labels = AllNodesLabelled(vec!("{x,y}", "{x}", "{y}", "{}"));
|
||||
let labels = AllNodesLabelled(vec!["{x,y}", "{x}", "{y}", "{}"]);
|
||||
let r = test_input(LabelledGraph::new("hasse_diagram",
|
||||
labels,
|
||||
vec![edge(0, 1, "", Style::None),
|
||||
|
@ -1033,7 +1041,7 @@ r#"digraph hasse_diagram {
|
|||
|
||||
#[test]
|
||||
fn left_aligned_text() {
|
||||
let labels = AllNodesLabelled(vec!(
|
||||
let labels = AllNodesLabelled(vec![
|
||||
"if test {\
|
||||
\\l branch1\
|
||||
\\l} else {\
|
||||
|
@ -1043,7 +1051,7 @@ r#"digraph hasse_diagram {
|
|||
\\l",
|
||||
"branch1",
|
||||
"branch2",
|
||||
"afterward"));
|
||||
"afterward"]);
|
||||
|
||||
let mut writer = Vec::new();
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ pub fn parse_logging_spec(spec: &str) -> (Vec<LogDirective>, Option<String>) {
|
|||
if let Some(m) = mods {
|
||||
for s in m.split(',') {
|
||||
if s.is_empty() {
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
let mut parts = s.split('=');
|
||||
let (log_level, name) = match (parts.next(),
|
||||
|
@ -69,13 +69,13 @@ pub fn parse_logging_spec(spec: &str) -> (Vec<LogDirective>, Option<String>) {
|
|||
Some(num) => (num, Some(part0)),
|
||||
_ => {
|
||||
println!("warning: invalid logging spec '{}', ignoring it", part1);
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
println!("warning: invalid logging spec '{}', ignoring it", s);
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
};
|
||||
dirs.push(LogDirective {
|
||||
|
|
|
@ -296,7 +296,7 @@ pub fn log(level: u32, loc: &'static LogLocation, args: fmt::Arguments) {
|
|||
n => {
|
||||
let filter = mem::transmute::<_, &String>(n);
|
||||
if !args.to_string().contains(filter) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ pub fn mod_enabled(level: u32, module: &str) -> bool {
|
|||
// check being expanded manually in the logging macro, this function checks
|
||||
// the log level again.
|
||||
if level > unsafe { LOG_LEVEL } {
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
|
||||
// This assertion should never get tripped unless we're in an at_exit
|
||||
|
@ -393,9 +393,7 @@ fn enabled(level: u32, module: &str, iter: slice::Iter<directive::LogDirective>)
|
|||
for directive in iter.rev() {
|
||||
match directive.name {
|
||||
Some(ref name) if !module.starts_with(&name[..]) => {}
|
||||
Some(..) | None => {
|
||||
return level <= directive.level
|
||||
}
|
||||
Some(..) | None => return level <= directive.level,
|
||||
}
|
||||
}
|
||||
level <= DEFAULT_LOG_LEVEL
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
|
||||
use {Rng, SeedableRng, Rand};
|
||||
|
||||
const KEY_WORDS : usize = 8; // 8 words for the 256-bit key
|
||||
const STATE_WORDS : usize = 16;
|
||||
const KEY_WORDS: usize = 8; // 8 words for the 256-bit key
|
||||
const STATE_WORDS: usize = 16;
|
||||
const CHACHA_ROUNDS: usize = 20; // Cryptographically secure from 8 upwards as of this writing
|
||||
|
||||
/// A random number generator that uses the ChaCha20 algorithm [1].
|
||||
|
@ -77,7 +77,6 @@ fn core(output: &mut [u32; STATE_WORDS], input: &[u32; STATE_WORDS]) {
|
|||
}
|
||||
|
||||
impl ChaChaRng {
|
||||
|
||||
/// Create an ChaCha random number generator using the default
|
||||
/// fixed key of 8 zero words.
|
||||
pub fn new_unseeded() -> ChaChaRng {
|
||||
|
@ -173,7 +172,6 @@ impl Rng for ChaChaRng {
|
|||
}
|
||||
|
||||
impl<'a> SeedableRng<&'a [u32]> for ChaChaRng {
|
||||
|
||||
fn reseed(&mut self, seed: &'a [u32]) {
|
||||
// reset state
|
||||
self.init(&[0; KEY_WORDS]);
|
||||
|
|
|
@ -89,7 +89,7 @@ impl Gamma {
|
|||
|
||||
let repr = match shape {
|
||||
1.0 => One(Exp::new(1.0 / scale)),
|
||||
0.0 ... 1.0 => Small(GammaSmallShape::new_raw(shape, scale)),
|
||||
0.0...1.0 => Small(GammaSmallShape::new_raw(shape, scale)),
|
||||
_ => Large(GammaLargeShape::new_raw(shape, scale)),
|
||||
};
|
||||
Gamma { repr: repr }
|
||||
|
@ -153,7 +153,8 @@ impl IndependentSample<f64> for GammaLargeShape {
|
|||
loop {
|
||||
let StandardNormal(x) = rng.gen::<StandardNormal>();
|
||||
let v_cbrt = 1.0 + self.c * x;
|
||||
if v_cbrt <= 0.0 { // a^3 <= 0 iff a <= 0
|
||||
if v_cbrt <= 0.0 {
|
||||
// a^3 <= 0 iff a <= 0
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -118,8 +118,10 @@ impl<'a, T: Clone> WeightedChoice<'a, T> {
|
|||
for item in &mut *items {
|
||||
running_total = match running_total.checked_add(item.weight) {
|
||||
Some(n) => n,
|
||||
None => panic!("WeightedChoice::new called with a total weight larger than a \
|
||||
usize can contain"),
|
||||
None => {
|
||||
panic!("WeightedChoice::new called with a total weight larger than a usize \
|
||||
can contain")
|
||||
}
|
||||
};
|
||||
|
||||
item.weight = running_total;
|
||||
|
@ -199,7 +201,6 @@ mod ziggurat_tables;
|
|||
/// * `pdf`: the probability density function
|
||||
/// * `zero_case`: manual sampling from the tail when we chose the
|
||||
/// bottom box (i.e. i == 0)
|
||||
|
||||
// the perf improvement (25-50%) is definitely worth the extra code
|
||||
// size from force-inlining.
|
||||
#[inline(always)]
|
||||
|
|
|
@ -54,7 +54,6 @@ static EMPTY: IsaacRng = IsaacRng {
|
|||
};
|
||||
|
||||
impl IsaacRng {
|
||||
|
||||
/// Create an ISAAC random number generator using the default
|
||||
/// fixed seed.
|
||||
pub fn new_unseeded() -> IsaacRng {
|
||||
|
|
|
@ -306,8 +306,7 @@ impl<'a, R: Rng> Iterator for AsciiGenerator<'a, R> {
|
|||
type Item = char;
|
||||
|
||||
fn next(&mut self) -> Option<char> {
|
||||
const GEN_ASCII_STR_CHARSET: &'static [u8] =
|
||||
b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\
|
||||
const GEN_ASCII_STR_CHARSET: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\
|
||||
abcdefghijklmnopqrstuvwxyz\
|
||||
0123456789";
|
||||
Some(*self.rng.choose(GEN_ASCII_STR_CHARSET).unwrap() as char)
|
||||
|
|
|
@ -202,7 +202,7 @@ tuple_impl!{A, B, C, D, E, F, G, H, I, J}
|
|||
tuple_impl!{A, B, C, D, E, F, G, H, I, J, K}
|
||||
tuple_impl!{A, B, C, D, E, F, G, H, I, J, K, L}
|
||||
|
||||
impl<T:Rand> Rand for Option<T> {
|
||||
impl<T: Rand> Rand for Option<T> {
|
||||
#[inline]
|
||||
fn rand<R: Rng>(rng: &mut R) -> Option<T> {
|
||||
if rng.gen() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue