newline_style: NewlineStyle, NewlineStyle::Unix, "Unix or Windows line endings";
fn_brace_style: BraceStyle, BraceStyle::SameLineWhere, "Brace style for functions";
item_brace_style: BraceStyle, BraceStyle::SameLineWhere, "Brace style for structs and enums";
+ fn_empty_single_line: bool, true, "Put empty-body functions on a single line";
fn_single_line: bool, false, "Put single-expression functions on a single line";
fn_return_indent: ReturnIndent, ReturnIndent::WithArgs,
"Location of return type in function declaration";
None
}
-// Checks that a block contains no statements, an expression and no comments.
-fn is_simple_block(block: &ast::Block, codemap: &CodeMap) -> bool {
- if !block.stmts.is_empty() || block.expr.is_none() {
- return false;
- }
-
+fn block_contains_comment(block: &ast::Block, codemap: &CodeMap) -> bool {
let snippet = codemap.span_to_snippet(block.span).unwrap();
+ contains_comment(&snippet)
+}
- !contains_comment(&snippet)
+// Checks that a block contains no statements, an expression and no comments.
+pub fn is_simple_block(block: &ast::Block, codemap: &CodeMap) -> bool {
+ block.stmts.is_empty() && block.expr.is_some() && !block_contains_comment(block, codemap)
}
/// Checks whether a block contains at most one statement or expression, and no comments.
pub fn is_simple_block_stmt(block: &ast::Block, codemap: &CodeMap) -> bool {
- if (!block.stmts.is_empty() && block.expr.is_some()) ||
- (block.stmts.len() != 1 && block.expr.is_none()) {
- return false;
- }
-
- let snippet = codemap.span_to_snippet(block.span).unwrap();
- !contains_comment(&snippet)
+ (block.stmts.is_empty() || (block.stmts.len() == 1 && block.expr.is_none())) &&
+ !block_contains_comment(block, codemap)
}
/// Checks whether a block contains no statements, expressions, or comments.
pub fn is_empty_block(block: &ast::Block, codemap: &CodeMap) -> bool {
- if !block.stmts.is_empty() || block.expr.is_some() {
- return false;
- }
-
- let snippet = codemap.span_to_snippet(block.span).unwrap();
- !contains_comment(&snippet)
+ block.stmts.is_empty() && block.expr.is_none() && !block_contains_comment(block, codemap)
}
// inter-match-arm-comment-rules:
}
pub fn rewrite_single_line_fn(&self,
- fn_rewrite: &Option<String>,
+ fn_str: &str,
block: &ast::Block)
-> Option<String> {
- let fn_str = match *fn_rewrite {
- Some(ref s) if !s.contains('\n') => s,
- _ => return None,
- };
+ if fn_str.contains('\n') {
+ return None;
+ }
let codemap = self.get_context().codemap;
- if is_empty_block(block, codemap) &&
- self.block_indent.width() + fn_str.len() + 3 <= self.config.max_width {
- return Some(format!("{}{{ }}", fn_str));
+ if self.config.fn_empty_single_line && is_empty_block(block, codemap) &&
+ self.block_indent.width() + fn_str.len() + 2 <= self.config.max_width {
+ return Some(format!("{}{{}}", fn_str));
}
if self.config.fn_single_line && is_simple_block_stmt(block, codemap) {
};
if let Some(res) = rewrite {
- let width = self.block_indent.width() + fn_str.len() + res.len() + 3;
+ let width = self.block_indent.width() + fn_str.len() + res.len() + 4;
if !res.contains('\n') && width <= self.config.max_width {
return Some(format!("{}{{ {} }}", fn_str, res));
}
visit::FnKind::Closure => None,
};
- if let Some(ref single_line_fn) = self.rewrite_single_line_fn(&rewrite, &b) {
- self.format_missing_with_indent(s.lo);
- self.buffer.push_str(single_line_fn);
- self.last_pos = b.span.hi;
- return;
- }
-
if let Some(fn_str) = rewrite {
self.format_missing_with_indent(s.lo);
- self.buffer.push_str(&fn_str);
+ if let Some(ref single_line_fn) = self.rewrite_single_line_fn(&fn_str, &b) {
+ self.buffer.push_str(single_line_fn);
+ self.last_pos = b.span.hi;
+ return;
+ } else {
+ self.buffer.push_str(&fn_str);
+ }
} else {
self.format_missing(b.span.lo);
}
/// Blah blah blooo.
/// Blah blah blooo.
#[an_attribute]
- fn foo(&mut self) -> isize { }
+ fn foo(&mut self) -> isize {}
/// Blah blah bing.
/// Blah blah bing.
}
#[another_attribute]
- fn f3(self) -> Dog { }
+ fn f3(self) -> Dog {}
/// Blah blah bing.
#[attrib1]
// Another comment that needs rewrite because it's tooooooooooooooooooooooooooooooo
// loooooooooooong.
/// Blah blah bing.
- fn f4(self) -> Cat { }
+ fn f4(self) -> Cat {}
}
}
/// test123
-fn doc_comment() { }
+fn doc_comment() {}
fn chains() {
foo.bar(|| {
}
-fn bar<F /* comment on F */, G /* comment on G */>() { }
+fn bar<F /* comment on F */, G /* comment on G */>() {}
-fn baz() -> Baz /* Comment after return type */ { }
+fn baz() -> Baz /* Comment after return type */ {}
arg(a, b, c, d, e)
}
-fn foo() -> ! { }
+fn foo() -> ! {}
pub fn http_fetch_async(listener: Box<AsyncCORSResponseListener + Send>,
script_chan: Box<ScriptChan + Send>) {
}
-fn some_func<T: Box<Trait + Bound>>(val: T) { }
+fn some_func<T: Box<Trait + Bound>>(val: T) {}
fn zzzzzzzzzzzzzzzzzzzz<Type, NodeType>(selff: Type,
mut handle: node::Handle<IdRef<'id, Node<K, V>>,
fn foo_decl_item(x: &mut i32) { x = 3; }
-fn empty() { }
+fn empty() {}
fn foo_return() -> String { "yay" }
fn mac() -> Vec<i32> { vec![] }
trait CoolTypes {
- fn dummy(&self) { }
+ fn dummy(&self) {}
}
trait CoolerTypes {
- fn dummy(&self) { }
+ fn dummy(&self) {}
}
// Tests different fns
-fn foo(a: AAAA, b: BBB, c: CCC) -> RetType { }
+fn foo(a: AAAA, b: BBB, c: CCC) -> RetType {}
fn foo(a: AAAA, b: BBB /* some, weird, inline comment */, c: CCC) -> RetType
where T: Blah
}
-fn foo<U: Fn(A) -> B /* paren inside generics */>() { }
+fn foo<U: Fn(A) -> B /* paren inside generics */>() {}
impl Foo {
fn with_no_errors<T, F>(&mut self, f: F) -> T
{
}
- fn foo(mut self, mut bar: u32) { }
+ fn foo(mut self, mut bar: u32) {}
- fn bar(self, mut bazz: u32) { }
+ fn bar(self, mut bazz: u32) {}
}
pub fn render<'a,
}
}
-fn homura<T: Deref<Target = i32>>(_: T) { }
+fn homura<T: Deref<Target = i32>>(_: T) {}
-fn issue377() -> (Box<CompositorProxy + Send>, Box<CompositorReceiver>) { }
+fn issue377() -> (Box<CompositorProxy + Send>, Box<CompositorReceiver>) {}
fn main() {
let _ = function(move || 5);
// sfdgfffffffffffffffffffffffffffffffffffffffffffffffffffffff
// ffffffffffffffffffffffffffffffffffffffffff
-fn foo(a: isize, b: u32 /* blah blah */, c: f64) { }
+fn foo(a: isize, b: u32 /* blah blah */, c: f64) {}
fn foo() -> Box<Write + 'static>
where 'a: 'b,
}
#[an_attribute]
- fn f3(self) -> Dog { }
+ fn f3(self) -> Dog {}
}
/// The `nodes` and `edges` method each return instantiations of
f: SomeType, // Comment beside a field
}
-fn foo(ann: &'a (PpAnn + 'a)) { }
+fn foo(ann: &'a (PpAnn + 'a)) {}
fn main() {
for i in 0i32..4 {
// A standard mod
-fn a() { }
+fn a() {}
// Another mod
-fn a() { }
+fn a() {}
use c::a;
-fn foo() { }
+fn foo() {}
-fn main() { }
+fn main() {}
let x: Foo<A>;
}
-fn op(foo: Bar, key: &[u8], upd: Fn(Option<&memcache::Item>, Baz) -> Result) -> MapResult { }
+fn op(foo: Bar, key: &[u8], upd: Fn(Option<&memcache::Item>, Baz) -> Result) -> MapResult {}