Break function headers earlier
Closes rustfmt#295.
This commit is contained in:
parent
36d65e4538
commit
76f303f369
55
src/items.rs
55
src/items.rs
@ -221,25 +221,23 @@ impl<'a> FmtVisitor<'a> {
|
||||
sig: &ast::MethodSig,
|
||||
span: Span)
|
||||
-> Option<String> {
|
||||
// Drop semicolon or it will be interpreted as comment
|
||||
// Drop semicolon or it will be interpreted as comment.
|
||||
let span = mk_sp(span.lo, span.hi - BytePos(1));
|
||||
let context = self.get_context();
|
||||
|
||||
// FIXME: silly formatting of the `.0`.
|
||||
let mut result = try_opt!(rewrite_fn_base(&context,
|
||||
indent,
|
||||
ident,
|
||||
&sig.decl,
|
||||
Some(&sig.explicit_self),
|
||||
&sig.generics,
|
||||
sig.unsafety,
|
||||
sig.constness,
|
||||
sig.abi,
|
||||
ast::Visibility::Inherited,
|
||||
span,
|
||||
false,
|
||||
false))
|
||||
.0;
|
||||
let (mut result, _) = try_opt!(rewrite_fn_base(&context,
|
||||
indent,
|
||||
ident,
|
||||
&sig.decl,
|
||||
Some(&sig.explicit_self),
|
||||
&sig.generics,
|
||||
sig.unsafety,
|
||||
sig.constness,
|
||||
sig.abi,
|
||||
ast::Visibility::Inherited,
|
||||
span,
|
||||
false,
|
||||
false));
|
||||
|
||||
// Re-attach semicolon
|
||||
result.push(';');
|
||||
@ -1050,7 +1048,7 @@ fn rewrite_fn_base(context: &RewriteContext,
|
||||
arg_indent);
|
||||
|
||||
// Check if vertical layout was forced by compute_budget_for_args.
|
||||
if one_line_budget <= 0 {
|
||||
if one_line_budget == 0 {
|
||||
if context.config.fn_args_paren_newline {
|
||||
result.push('\n');
|
||||
result.push_str(&arg_indent.to_string(context.config));
|
||||
@ -1305,28 +1303,21 @@ fn compute_budgets_for_args(context: &RewriteContext,
|
||||
ret_str_len: usize,
|
||||
newline_brace: bool)
|
||||
-> (usize, usize, Indent) {
|
||||
// Try keeping everything on the same line
|
||||
// Try keeping everything on the same line.
|
||||
if !result.contains("\n") {
|
||||
// 3 = `() `, space is before ret_string
|
||||
// 3 = `() `, space is before ret_string.
|
||||
let mut used_space = indent.width() + result.len() + ret_str_len + 3;
|
||||
if !newline_brace {
|
||||
used_space += 2;
|
||||
}
|
||||
let one_line_budget = if used_space > context.config.max_width {
|
||||
0
|
||||
} else {
|
||||
context.config.max_width - used_space
|
||||
};
|
||||
let one_line_budget = context.config.max_width.checked_sub(used_space).unwrap_or(0);
|
||||
|
||||
if one_line_budget > 0 {
|
||||
let multi_line_budget = context.config.max_width -
|
||||
(indent.width() + result.len() + "()".len());
|
||||
|
||||
// 2 = `()`
|
||||
let used_space = indent.width() + result.len() + 2;
|
||||
let max_space = context.config.max_width;
|
||||
debug!("compute_budgets_for_args: used_space: {}, max_space: {}",
|
||||
used_space,
|
||||
max_space);
|
||||
if used_space < max_space {
|
||||
return (one_line_budget,
|
||||
max_space - used_space,
|
||||
multi_line_budget,
|
||||
indent + result.len() + 1);
|
||||
}
|
||||
}
|
||||
|
@ -41,3 +41,5 @@ unsafe fn generic_call(cx: *mut JSContext, argc: libc::c_uint, vp: *mut JSVal,
|
||||
-> u8) {
|
||||
let f: fn ( _ , _ ) -> _ = panic!() ;
|
||||
}
|
||||
|
||||
pub fn start_export_thread<C: CryptoSchemee + 'static>(database: &Database, crypto_scheme: &C, block_size: usize, source_path: &Path) -> BonzoResult<mpsc::Consumer<'static, FileInstruction>> {}
|
||||
|
@ -64,3 +64,11 @@ unsafe fn generic_call(cx: *mut JSContext,
|
||||
-> u8) {
|
||||
let f: fn(_, _) -> _ = panic!();
|
||||
}
|
||||
|
||||
pub fn start_export_thread<C: CryptoSchemee + 'static>
|
||||
(database: &Database,
|
||||
crypto_scheme: &C,
|
||||
block_size: usize,
|
||||
source_path: &Path)
|
||||
-> BonzoResult<mpsc::Consumer<'static, FileInstruction>> {
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user