Force chains to adhere to restrictions
This commit is contained in:
parent
6e1f77664d
commit
7b0cceafee
@ -21,7 +21,7 @@
|
||||
|
||||
use Indent;
|
||||
use rewrite::{Rewrite, RewriteContext};
|
||||
use utils::first_line_width;
|
||||
use utils::{wrap_str, first_line_width};
|
||||
use expr::rewrite_call;
|
||||
use config::BlockIndentStyle;
|
||||
|
||||
@ -58,12 +58,8 @@ pub fn rewrite_chain(mut expr: &ast::Expr,
|
||||
} else {
|
||||
match context.config.chain_indent {
|
||||
BlockIndentStyle::Inherit => (context.block_indent, false),
|
||||
BlockIndentStyle::Tabbed => {
|
||||
(context.block_indent.block_indent(context.config), false)
|
||||
}
|
||||
BlockIndentStyle::Visual => {
|
||||
(offset + Indent::new(context.config.tab_spaces, 0), false)
|
||||
}
|
||||
BlockIndentStyle::Tabbed => (context.block_indent.block_indent(context.config), false),
|
||||
BlockIndentStyle::Visual => (offset + Indent::new(context.config.tab_spaces, 0), false),
|
||||
}
|
||||
};
|
||||
|
||||
@ -142,10 +138,13 @@ pub fn rewrite_chain(mut expr: &ast::Expr,
|
||||
&connector[..]
|
||||
};
|
||||
|
||||
Some(format!("{}{}{}",
|
||||
parent_rewrite,
|
||||
first_connector,
|
||||
rewrites.join(&connector)))
|
||||
wrap_str(format!("{}{}{}",
|
||||
parent_rewrite,
|
||||
first_connector,
|
||||
rewrites.join(&connector)),
|
||||
context.config.max_width,
|
||||
width,
|
||||
offset)
|
||||
}
|
||||
|
||||
// States whether an expression's last line exclusively consists of closing
|
||||
|
14
src/items.rs
14
src/items.rs
@ -875,12 +875,14 @@ impl<'a> FmtVisitor<'a> {
|
||||
offset + header_str.len(),
|
||||
mk_sp(span.lo, body_lo)))
|
||||
}
|
||||
None => if self.config.item_brace_style == BraceStyle::AlwaysNextLine &&
|
||||
!fields.is_empty() {
|
||||
format!("\n{}{{", self.block_indent.to_string(self.config))
|
||||
} else {
|
||||
" {".to_owned()
|
||||
},
|
||||
None => {
|
||||
if self.config.item_brace_style == BraceStyle::AlwaysNextLine &&
|
||||
!fields.is_empty() {
|
||||
format!("\n{}{{", self.block_indent.to_string(self.config))
|
||||
} else {
|
||||
" {".to_owned()
|
||||
}
|
||||
}
|
||||
};
|
||||
result.push_str(&generics_str);
|
||||
|
||||
|
@ -11,7 +11,6 @@ fn foo() {
|
||||
an_expression;
|
||||
foo()
|
||||
}
|
||||
// Perhaps this should introduce braces?
|
||||
Foo(ref bar) =>
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
|
||||
Pattern1 | Pattern2 | Pattern3 => false,
|
||||
@ -83,7 +82,11 @@ fn main() {
|
||||
"scopeid"),
|
||||
true,
|
||||
true),
|
||||
}
|
||||
};
|
||||
|
||||
match x{
|
||||
y=>{/*Block with comment. Preserve me.*/ }
|
||||
z=>{stmt();} }
|
||||
}
|
||||
|
||||
fn matches() {
|
||||
|
@ -12,7 +12,6 @@ fn foo() {
|
||||
an_expression;
|
||||
foo()
|
||||
}
|
||||
// Perhaps this should introduce braces?
|
||||
Foo(ref bar) => {
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
}
|
||||
@ -93,6 +92,15 @@ fn main() {
|
||||
true,
|
||||
true)
|
||||
}
|
||||
};
|
||||
|
||||
match x {
|
||||
y => {
|
||||
// Block with comment. Preserve me.
|
||||
}
|
||||
z => {
|
||||
stmt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user