Format source codes and add a test

This commit is contained in:
topecongiro 2017-06-15 23:29:46 +09:00
parent 2f17c31fa4
commit 0d5768964b
3 changed files with 30 additions and 11 deletions

View File

@ -750,14 +750,14 @@ fn and_one_line(x: Option<String>) -> Option<String> {
fn nop_block_collapse(block_str: Option<String>, budget: usize) -> Option<String> {
debug!("nop_block_collapse {:?} {}", block_str, budget);
block_str.map(|block_str| if block_str.starts_with('{') && budget >= 2 &&
(block_str[1..]
.find(|c: char| !c.is_whitespace())
.unwrap() == block_str.len() - 2)
{
"{}".to_owned()
} else {
block_str.to_owned()
block_str.map(|block_str| {
if block_str.starts_with('{') && budget >= 2 &&
(block_str[1..].find(|c: char| !c.is_whitespace()).unwrap() == block_str.len() - 2)
{
"{}".to_owned()
} else {
block_str.to_owned()
}
})
}

View File

@ -159,9 +159,9 @@ impl Rewrite for ast::ViewPath {
// Returns an empty string when the ViewPath is empty (like foo::bar::{})
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
match self.node {
ast::ViewPath_::ViewPathList(_, ref path_list) if path_list.is_empty() => {
Some(String::new())
}
ast::ViewPath_::ViewPathList(_, ref path_list) if path_list.is_empty() => Some(
String::new(),
),
ast::ViewPath_::ViewPathList(ref path, ref path_list) => {
rewrite_use_list(shape, path, path_list, self.span, context)
}

View File

@ -0,0 +1,19 @@
// rustfmt-max_width: 80
fn foo() {
// This is where it gets good
refmut_map_result(self.cache.borrow_mut(), |cache| {
match cache.entry(cache_key) {
Occupied(entry) => Ok(entry.into_mut()),
Vacant(entry) => {
let statement = {
let sql = try!(entry.key().sql(source));
prepare_fn(&sql)
};
Ok(entry.insert(try!(statement)))
}
// and now, casually call a method on this
}
}).map(MaybeCached::Cached)
}