1
Fork 0

Combine rewrite_single_line_fn and rewrite_fn

This commit is contained in:
Kevin Yeh 2015-11-19 20:49:24 -06:00
parent 15ec5b2912
commit 2e9b6dfab4
2 changed files with 14 additions and 14 deletions

View file

@ -177,7 +177,8 @@ impl<'a> FmtVisitor<'a> {
constness: ast::Constness, constness: ast::Constness,
abi: abi::Abi, abi: abi::Abi,
vis: ast::Visibility, vis: ast::Visibility,
span: Span) span: Span,
block: &ast::Block)
-> Option<String> { -> Option<String> {
let mut newline_brace = self.newline_for_brace(&generics.where_clause); let mut newline_brace = self.newline_for_brace(&generics.where_clause);
@ -212,7 +213,7 @@ impl<'a> FmtVisitor<'a> {
result.push(' '); result.push(' ');
} }
Some(result) self.single_line_fn(&result, block).or_else(|| Some(result))
} }
pub fn rewrite_required_fn(&mut self, pub fn rewrite_required_fn(&mut self,
@ -447,10 +448,7 @@ impl<'a> FmtVisitor<'a> {
Some((result, force_new_line_for_brace)) Some((result, force_new_line_for_brace))
} }
pub fn rewrite_single_line_fn(&self, fn single_line_fn(&self, fn_str: &str, block: &ast::Block) -> Option<String> {
fn_str: &str,
block: &ast::Block)
-> Option<String> {
if fn_str.contains('\n') { if fn_str.contains('\n') {
return None; return None;

View file

@ -137,7 +137,8 @@ impl<'a> FmtVisitor<'a> {
constness, constness,
abi, abi,
vis, vis,
codemap::mk_sp(s.lo, b.span.lo)) codemap::mk_sp(s.lo, b.span.lo),
&b)
} }
visit::FnKind::Method(ident, ref sig, vis) => { visit::FnKind::Method(ident, ref sig, vis) => {
self.rewrite_fn(indent, self.rewrite_fn(indent,
@ -149,19 +150,20 @@ impl<'a> FmtVisitor<'a> {
sig.constness, sig.constness,
sig.abi, sig.abi,
vis.unwrap_or(ast::Visibility::Inherited), vis.unwrap_or(ast::Visibility::Inherited),
codemap::mk_sp(s.lo, b.span.lo)) codemap::mk_sp(s.lo, b.span.lo),
&b)
} }
visit::FnKind::Closure => None, visit::FnKind::Closure => None,
}; };
if let Some(fn_str) = rewrite { if let Some(fn_str) = rewrite {
self.format_missing_with_indent(s.lo); self.format_missing_with_indent(s.lo);
if let Some(ref single_line_fn) = self.rewrite_single_line_fn(&fn_str, &b) { self.buffer.push_str(&fn_str);
self.buffer.push_str(single_line_fn); if let Some(c) = fn_str.chars().last() {
if c == '}' {
self.last_pos = b.span.hi; self.last_pos = b.span.hi;
return; return;
} else { }
self.buffer.push_str(&fn_str);
} }
} else { } else {
self.format_missing(b.span.lo); self.format_missing(b.span.lo);