Merge pull request #384 from nrc/where-empty
Option for putting the where clause on the same line as the function …
This commit is contained in:
commit
10eb21d020
@ -74,6 +74,8 @@ pub enum Density {
|
||||
Compressed,
|
||||
// Use more lines.
|
||||
Tall,
|
||||
// Try to compress if the body is empty.
|
||||
CompressedIfEmpty,
|
||||
}
|
||||
|
||||
impl_enum_decodable!(Density, Compressed, Tall);
|
||||
@ -82,7 +84,7 @@ impl Density {
|
||||
pub fn to_list_tactic(self) -> ListTactic {
|
||||
match self {
|
||||
Density::Compressed => ListTactic::Mixed,
|
||||
Density::Tall => ListTactic::HorizontalVertical,
|
||||
Density::Tall | Density::CompressedIfEmpty => ListTactic::HorizontalVertical,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -267,7 +269,7 @@ impl Default for Config {
|
||||
fn_args_density: Density::Tall,
|
||||
fn_args_layout: StructLitStyle::Visual,
|
||||
fn_arg_indent: BlockIndentStyle::Visual,
|
||||
where_density: Density::Tall,
|
||||
where_density: Density::CompressedIfEmpty,
|
||||
where_indent: BlockIndentStyle::Tabbed,
|
||||
where_layout: ListTactic::Vertical,
|
||||
where_pred_indent: BlockIndentStyle::Visual,
|
||||
|
12
src/items.rs
12
src/items.rs
@ -144,6 +144,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
abi::Abi::Rust,
|
||||
ast::Visibility::Inherited,
|
||||
span,
|
||||
false,
|
||||
false);
|
||||
|
||||
match rewrite {
|
||||
@ -210,7 +211,8 @@ impl<'a> FmtVisitor<'a> {
|
||||
abi,
|
||||
vis,
|
||||
span,
|
||||
newline_brace));
|
||||
newline_brace,
|
||||
true));
|
||||
|
||||
if self.config.fn_brace_style != BraceStyle::AlwaysNextLine && !result.contains('\n') {
|
||||
newline_brace = false;
|
||||
@ -250,6 +252,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
sig.abi,
|
||||
ast::Visibility::Inherited,
|
||||
span,
|
||||
false,
|
||||
false));
|
||||
|
||||
// Re-attach semicolon
|
||||
@ -269,7 +272,8 @@ impl<'a> FmtVisitor<'a> {
|
||||
abi: abi::Abi,
|
||||
vis: ast::Visibility,
|
||||
span: Span,
|
||||
newline_brace: bool)
|
||||
newline_brace: bool,
|
||||
has_body: bool)
|
||||
-> Option<String> {
|
||||
// FIXME we'll lose any comments in between parts of the function decl, but anyone
|
||||
// who comments there probably deserves what they get.
|
||||
@ -407,7 +411,9 @@ impl<'a> FmtVisitor<'a> {
|
||||
(!result.contains('\n') ||
|
||||
self.config.fn_args_layout == StructLitStyle::Block)) ||
|
||||
(self.config.fn_args_layout == StructLitStyle::Block &&
|
||||
ret_str.is_empty()) {
|
||||
ret_str.is_empty()) ||
|
||||
(self.config.where_density == Density::CompressedIfEmpty &&
|
||||
!has_body) {
|
||||
Density::Compressed
|
||||
} else {
|
||||
Density::Tall
|
||||
|
@ -15,8 +15,7 @@ trait Foo {
|
||||
|
||||
fn increment(&mut self, x: i32);
|
||||
|
||||
fn read(&mut self, x: BufReader<R> /* Used to be MemReader */)
|
||||
where R: Read;
|
||||
fn read(&mut self, x: BufReader<R> /* Used to be MemReader */) where R: Read;
|
||||
}
|
||||
|
||||
pub trait WriteMessage {
|
||||
|
Loading…
x
Reference in New Issue
Block a user