Skip to content

Commit 8df498b

Browse files
more fixes for everybody_loops
1 parent f3733a2 commit 8df498b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/librustc_driver/pretty.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,10 @@ impl<'a> ReplaceBodyWithLoop<'a> {
666666

667667
fn run<R, F: FnOnce(&mut Self) -> R>(&mut self, is_const: bool, action: F) -> R {
668668
let old_const = mem::replace(&mut self.within_static_or_const, is_const);
669+
let old_blocks = self.nested_blocks.take();
669670
let ret = action(self);
670671
self.within_static_or_const = old_const;
672+
self.nested_blocks = old_blocks;
671673
ret
672674
}
673675

@@ -745,6 +747,10 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> {
745747
self.run(is_const, |s| fold::noop_fold_impl_item(i, s))
746748
}
747749

750+
fn fold_anon_const(&mut self, c: ast::AnonConst) -> ast::AnonConst {
751+
self.run(true, |s| fold::noop_fold_anon_const(c, s))
752+
}
753+
748754
fn fold_block(&mut self, b: P<ast::Block>) -> P<ast::Block> {
749755
fn stmt_to_block(rules: ast::BlockCheckMode,
750756
recovered: bool,
@@ -811,7 +817,9 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> {
811817

812818
if let Some(old_blocks) = self.nested_blocks.as_mut() {
813819
//push our fresh block onto the cache and yield an empty block with `loop {}`
814-
old_blocks.push(new_block);
820+
if !new_block.stmts.is_empty() {
821+
old_blocks.push(new_block);
822+
}
815823

816824
stmt_to_block(b.rules, b.recovered, Some(loop_stmt), self.sess)
817825
} else {

0 commit comments

Comments
 (0)