Skip to content

Commit

Permalink
Merge pull request rust-lang#3334 from rchaser53/issue-3227
Browse files Browse the repository at this point in the history
fix Inconsistency between  loop  and while
  • Loading branch information
scampi authored Feb 15, 2019
2 parents d6829d6 + c4b6b52 commit e5284b1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -376,22 +377,23 @@ fn is_block_closure_forced(context: &RewriteContext<'_>, expr: &ast::Expr) -> bo
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,
}
}
13 changes: 13 additions & 0 deletions tests/source/issue-3227/two.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// rustfmt-version: Two

fn main() {
thread::spawn(|| {
while true {
println!("iteration");
}
});

thread::spawn(|| loop {
println!("iteration");
});
}
13 changes: 13 additions & 0 deletions tests/target/issue-3227/one.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// rustfmt-version: One

fn main() {
thread::spawn(|| {
while true {
println!("iteration");
}
});

thread::spawn(|| loop {
println!("iteration");
});
}
15 changes: 15 additions & 0 deletions tests/target/issue-3227/two.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// rustfmt-version: Two

fn main() {
thread::spawn(|| {
while true {
println!("iteration");
}
});

thread::spawn(|| {
loop {
println!("iteration");
}
});
}

0 comments on commit e5284b1

Please sign in to comment.