Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e5284b1

Browse files
authored
Merge pull request rust-lang#3334 from rchaser53/issue-3227
fix Inconsistency between loop and while
2 parents d6829d6 + c4b6b52 commit e5284b1

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

src/closures.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use syntax::source_map::Span;
1313
use syntax::{ast, ptr};
1414

1515
use crate::config::lists::*;
16+
use crate::config::Version;
1617
use crate::expr::{block_contains_comment, is_simple_block, is_unsafe_block, rewrite_cond};
1718
use crate::items::{span_hi_for_arg, span_lo_for_arg};
1819
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) -> bo
376377
if context.inside_macro() {
377378
false
378379
} else {
379-
is_block_closure_forced_inner(expr)
380+
is_block_closure_forced_inner(expr, context.config.version())
380381
}
381382
}
382383

383-
fn is_block_closure_forced_inner(expr: &ast::Expr) -> bool {
384+
fn is_block_closure_forced_inner(expr: &ast::Expr, version: Version) -> bool {
384385
match expr.node {
385386
ast::ExprKind::If(..)
386387
| ast::ExprKind::IfLet(..)
387388
| ast::ExprKind::While(..)
388389
| ast::ExprKind::WhileLet(..)
389390
| ast::ExprKind::ForLoop(..) => true,
391+
ast::ExprKind::Loop(..) if version == Version::Two => true,
390392
ast::ExprKind::AddrOf(_, ref expr)
391393
| ast::ExprKind::Box(ref expr)
392394
| ast::ExprKind::Try(ref expr)
393395
| ast::ExprKind::Unary(_, ref expr)
394-
| ast::ExprKind::Cast(ref expr, _) => is_block_closure_forced_inner(expr),
396+
| ast::ExprKind::Cast(ref expr, _) => is_block_closure_forced_inner(expr, version),
395397
_ => false,
396398
}
397399
}

tests/source/issue-3227/two.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// rustfmt-version: Two
2+
3+
fn main() {
4+
thread::spawn(|| {
5+
while true {
6+
println!("iteration");
7+
}
8+
});
9+
10+
thread::spawn(|| loop {
11+
println!("iteration");
12+
});
13+
}

tests/target/issue-3227/one.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// rustfmt-version: One
2+
3+
fn main() {
4+
thread::spawn(|| {
5+
while true {
6+
println!("iteration");
7+
}
8+
});
9+
10+
thread::spawn(|| loop {
11+
println!("iteration");
12+
});
13+
}

tests/target/issue-3227/two.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// rustfmt-version: Two
2+
3+
fn main() {
4+
thread::spawn(|| {
5+
while true {
6+
println!("iteration");
7+
}
8+
});
9+
10+
thread::spawn(|| {
11+
loop {
12+
println!("iteration");
13+
}
14+
});
15+
}

0 commit comments

Comments
 (0)