diff options
| author | rchaser53 <tayoshizawa29@gmail.com> | 2019-02-08 21:39:11 +0900 |
|---|---|---|
| committer | rchaser53 <tayoshizawa29@gmail.com> | 2019-02-14 10:06:29 +0900 |
| commit | 7d9a2ef96d8106fe399a0e97fc4087a76361c4e2 (patch) | |
| tree | 128ccb245b06aa1ca3efe93929fdddf5156b6e4f | |
| parent | e28fae99747af538a30452413692a015da93b490 (diff) | |
version/2: Align loop and while formatting
The loop and while formatting was diverting as `loop` was not being moved to a new, indented block, as `while` was. This commit fixes this inconsistency but pins it to version 2 to avoid changing existing code.
| -rw-r--r-- | src/closures.rs | 8 | ||||
| -rw-r--r-- | tests/source/issue-3227/one.rs | 13 | ||||
| -rw-r--r-- | tests/source/issue-3227/two.rs | 13 | ||||
| -rw-r--r-- | tests/target/issue-3227/one.rs | 13 | ||||
| -rw-r--r-- | tests/target/issue-3227/two.rs | 15 |
5 files changed, 59 insertions, 3 deletions
diff --git a/src/closures.rs b/src/closures.rs index a0489718740..e74d0f7a44d 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -13,6 +13,7 @@ use syntax::source_map::Span; use syntax::{ast, ptr}; use crate::config::lists::*; +use crate::config::Version; use crate::expr::{block_contains_comment, is_simple_block, is_unsafe_block, rewrite_cond}; use crate::items::{span_hi_for_arg, span_lo_for_arg}; use crate::lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator}; @@ -376,22 +377,23 @@ fn is_block_closure_forced(context: &RewriteContext, expr: &ast::Expr) -> bool { if context.inside_macro() { false } else { - is_block_closure_forced_inner(expr) + is_block_closure_forced_inner(expr, context.config.version()) } } -fn is_block_closure_forced_inner(expr: &ast::Expr) -> bool { +fn is_block_closure_forced_inner(expr: &ast::Expr, version: Version) -> bool { match expr.node { ast::ExprKind::If(..) | ast::ExprKind::IfLet(..) | ast::ExprKind::While(..) | ast::ExprKind::WhileLet(..) | ast::ExprKind::ForLoop(..) => true, + ast::ExprKind::Loop(..) if version == Version::Two => true, ast::ExprKind::AddrOf(_, ref expr) | ast::ExprKind::Box(ref expr) | ast::ExprKind::Try(ref expr) | ast::ExprKind::Unary(_, ref expr) - | ast::ExprKind::Cast(ref expr, _) => is_block_closure_forced_inner(expr), + | ast::ExprKind::Cast(ref expr, _) => is_block_closure_forced_inner(expr, version), _ => false, } } diff --git a/tests/source/issue-3227/one.rs b/tests/source/issue-3227/one.rs new file mode 100644 index 00000000000..fcc8331000d --- /dev/null +++ b/tests/source/issue-3227/one.rs @@ -0,0 +1,13 @@ +// rustfmt-version: One + +fn main() { + thread::spawn(|| { + while true { + println!("iteration"); + } + }); + + thread::spawn(|| loop { + println!("iteration"); + }); +} diff --git a/tests/source/issue-3227/two.rs b/tests/source/issue-3227/two.rs new file mode 100644 index 00000000000..c1572c00d57 --- /dev/null +++ b/tests/source/issue-3227/two.rs @@ -0,0 +1,13 @@ +// rustfmt-version: Two + +fn main() { + thread::spawn(|| { + while true { + println!("iteration"); + } + }); + + thread::spawn(|| loop { + println!("iteration"); + }); +} diff --git a/tests/target/issue-3227/one.rs b/tests/target/issue-3227/one.rs new file mode 100644 index 00000000000..fcc8331000d --- /dev/null +++ b/tests/target/issue-3227/one.rs @@ -0,0 +1,13 @@ +// rustfmt-version: One + +fn main() { + thread::spawn(|| { + while true { + println!("iteration"); + } + }); + + thread::spawn(|| loop { + println!("iteration"); + }); +} diff --git a/tests/target/issue-3227/two.rs b/tests/target/issue-3227/two.rs new file mode 100644 index 00000000000..374ab54305d --- /dev/null +++ b/tests/target/issue-3227/two.rs @@ -0,0 +1,15 @@ +// rustfmt-version: Two + +fn main() { + thread::spawn(|| { + while true { + println!("iteration"); + } + }); + + thread::spawn(|| { + loop { + println!("iteration"); + } + }); +} |
