mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-25 05:14:27 +00:00
Prevent line breaking at =
or in
after trivial patterns
This commit is contained in:
parent
4418fab4f2
commit
b6bffa6596
22
src/expr.rs
22
src/expr.rs
@ -1307,20 +1307,28 @@ fn rewrite_pat_expr(context: &RewriteContext,
|
|||||||
offset + extra_offset + spacer.len());
|
offset + extra_offset + spacer.len());
|
||||||
|
|
||||||
if let Some(expr_string) = expr_rewrite {
|
if let Some(expr_string) = expr_rewrite {
|
||||||
result.push_str(spacer);
|
let pat_simple =
|
||||||
result.push_str(&expr_string);
|
pat.and_then(|p| p.rewrite(context, context.config.max_width, Indent::empty()))
|
||||||
return Some(result);
|
.map(|s| pat_is_simple(&s));
|
||||||
|
|
||||||
|
if pat.is_none() || pat_simple.unwrap_or(false) || !expr_string.contains('\n') {
|
||||||
|
result.push_str(spacer);
|
||||||
|
result.push_str(&expr_string);
|
||||||
|
return Some(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let nested = context.nested_context();
|
||||||
|
|
||||||
// The expression won't fit on the current line, jump to next.
|
// The expression won't fit on the current line, jump to next.
|
||||||
result.push('\n');
|
result.push('\n');
|
||||||
result.push_str(&pat_offset.to_string(context.config));
|
result.push_str(&nested.block_indent.to_string(context.config));
|
||||||
|
|
||||||
let expr_rewrite =
|
let expr_rewrite =
|
||||||
expr.rewrite(context,
|
expr.rewrite(&nested,
|
||||||
try_opt!(context.config.max_width.checked_sub(pat_offset.width())),
|
try_opt!(context.config.max_width.checked_sub(nested.block_indent.width())),
|
||||||
pat_offset);
|
nested.block_indent);
|
||||||
result.push_str(&try_opt!(expr_rewrite));
|
result.push_str(&try_opt!(expr_rewrite));
|
||||||
|
|
||||||
Some(result)
|
Some(result)
|
||||||
|
@ -568,7 +568,7 @@ fn format_impl_ref_and_type(context: &RewriteContext,
|
|||||||
split_at_for: bool)
|
split_at_for: bool)
|
||||||
-> Option<String> {
|
-> Option<String> {
|
||||||
if let ast::ItemKind::Impl(unsafety, polarity, ref generics, ref trait_ref, ref self_ty, _) =
|
if let ast::ItemKind::Impl(unsafety, polarity, ref generics, ref trait_ref, ref self_ty, _) =
|
||||||
item.node {
|
item.node {
|
||||||
let mut result = String::new();
|
let mut result = String::new();
|
||||||
|
|
||||||
result.push_str(&*format_visibility(&item.vis));
|
result.push_str(&*format_visibility(&item.vis));
|
||||||
@ -670,7 +670,7 @@ pub fn format_struct(context: &RewriteContext,
|
|||||||
|
|
||||||
pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent) -> Option<String> {
|
pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent) -> Option<String> {
|
||||||
if let ast::ItemKind::Trait(unsafety, ref generics, ref type_param_bounds, ref trait_items) =
|
if let ast::ItemKind::Trait(unsafety, ref generics, ref type_param_bounds, ref trait_items) =
|
||||||
item.node {
|
item.node {
|
||||||
let mut result = String::new();
|
let mut result = String::new();
|
||||||
let header = format!("{}{}trait {}",
|
let header = format!("{}{}trait {}",
|
||||||
format_visibility(&item.vis),
|
format_visibility(&item.vis),
|
||||||
|
@ -285,3 +285,16 @@ fn complex_if_else() {
|
|||||||
yo();
|
yo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn issue1106() {
|
||||||
|
{
|
||||||
|
if let hir::ItemEnum(ref enum_def, ref generics) = self.ast_map.expect_item(enum_node_id).node {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for entry in
|
||||||
|
WalkDir::new(path)
|
||||||
|
.into_iter()
|
||||||
|
.filter_entry(|entry| exclusions.filter_entry(entry)) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -55,8 +55,8 @@ fn foo() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let (some_very_large,
|
if let (some_very_large,
|
||||||
tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1111 +
|
tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) =
|
||||||
2222 {}
|
1111 + 2222 {}
|
||||||
|
|
||||||
if let (some_very_large,
|
if let (some_very_large,
|
||||||
tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1 + 2 + 3 {
|
tuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuple) = 1 + 2 + 3 {
|
||||||
@ -283,10 +283,23 @@ fn complex_if_else() {
|
|||||||
} else if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + xxxxxxxx {
|
} else if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + xxxxxxxx {
|
||||||
yo();
|
yo();
|
||||||
} else if let Some(x) =
|
} else if let Some(x) =
|
||||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx {
|
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx {
|
||||||
ha();
|
ha();
|
||||||
} else if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +
|
} else if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +
|
||||||
xxxxxxxxx {
|
xxxxxxxxx {
|
||||||
yo();
|
yo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn issue1106() {
|
||||||
|
{
|
||||||
|
if let hir::ItemEnum(ref enum_def, ref generics) =
|
||||||
|
self.ast_map.expect_item(enum_node_id).node {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for entry in WalkDir::new(path)
|
||||||
|
.into_iter()
|
||||||
|
.filter_entry(|entry| exclusions.filter_entry(entry)) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -21,8 +21,8 @@ fn main() {
|
|||||||
while aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa {
|
while aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa {
|
||||||
}
|
}
|
||||||
|
|
||||||
'b: for xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx in some_iter(arg1,
|
'b: for xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx in
|
||||||
arg2) {
|
some_iter(arg1, arg2) {
|
||||||
// do smth
|
// do smth
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user