Skip to content

Commit fd834ee

Browse files
committed
Don't generate fake IDs in ReplaceBodyWithLoop
1 parent 6dac78b commit fd834ee

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/librustc_interface/util.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use log::info;
22
use rustc_ast::ast::{AttrVec, BlockCheckMode};
3-
use rustc_ast::mut_visit::{visit_clobber, MutVisitor, *};
3+
use rustc_ast::mut_visit::{/*visit_clobber,*/ MutVisitor, *};
44
use rustc_ast::ptr::P;
55
use rustc_ast::util::lev_distance::find_best_match_for_name;
66
use rustc_ast::{self, ast};
@@ -29,7 +29,7 @@ use smallvec::SmallVec;
2929
use std::env;
3030
use std::io::{self, Write};
3131
use std::mem;
32-
use std::ops::DerefMut;
32+
//use std::ops::DerefMut;
3333
use std::path::{Path, PathBuf};
3434
use std::sync::{Arc, Mutex, Once};
3535
#[cfg(not(parallel_compiler))]
@@ -593,7 +593,7 @@ pub fn build_output_filenames(
593593
// [#34511]: https://github.com/rust-lang/rust/issues/34511#issuecomment-322340401
594594
pub struct ReplaceBodyWithLoop<'a, 'b> {
595595
within_static_or_const: bool,
596-
nested_blocks: Option<Vec<ast::Block>>,
596+
nested_blocks: Option<Vec<ast::Stmt>>,
597597
resolver: &'a mut Resolver<'b>,
598598
}
599599

@@ -707,6 +707,7 @@ impl<'a> MutVisitor for ReplaceBodyWithLoop<'a, '_> {
707707
}
708708
}
709709

710+
/*
710711
fn block_to_stmt(b: ast::Block, resolver: &mut Resolver<'_>) -> ast::Stmt {
711712
let expr = P(ast::Expr {
712713
id: resolver.next_node_id(),
@@ -722,6 +723,7 @@ impl<'a> MutVisitor for ReplaceBodyWithLoop<'a, '_> {
722723
span: rustc_span::DUMMY_SP,
723724
}
724725
}
726+
*/
725727

726728
let empty_block = stmt_to_block(BlockCheckMode::Default, None, self.resolver);
727729
let loop_expr = P(ast::Expr {
@@ -741,35 +743,37 @@ impl<'a> MutVisitor for ReplaceBodyWithLoop<'a, '_> {
741743
if self.within_static_or_const {
742744
noop_visit_block(b, self)
743745
} else {
744-
visit_clobber(b.deref_mut(), |b| {
746+
//visit_clobber(b.deref_mut(), |b| {
745747
let mut stmts = vec![];
746-
for s in b.stmts {
748+
for s in b.stmts.drain(..) {
747749
let old_blocks = self.nested_blocks.replace(vec![]);
748750

749751
stmts.extend(self.flat_map_stmt(s).into_iter().filter(|s| s.is_item()));
750752

751753
// we put a Some in there earlier with that replace(), so this is valid
752754
let new_blocks = self.nested_blocks.take().unwrap();
753755
self.nested_blocks = old_blocks;
754-
stmts.extend(new_blocks.into_iter().map(|b| block_to_stmt(b, self.resolver)));
756+
stmts.extend(new_blocks); //.into_iter().map(|b| block_to_stmt(b, self.resolver)));
755757
}
756758

757-
let mut new_block = ast::Block { stmts, ..b };
759+
//let mut new_block = ast::Block { stmts, ..b };
758760

759761
if let Some(old_blocks) = self.nested_blocks.as_mut() {
760762
//push our fresh block onto the cache and yield an empty block with `loop {}`
761-
if !new_block.stmts.is_empty() {
762-
old_blocks.push(new_block);
763+
if !stmts.is_empty() {
764+
//old_blocks.push(new_block);
765+
old_blocks.extend(stmts);
763766
}
764767

765-
stmt_to_block(b.rules, Some(loop_stmt), &mut self.resolver)
768+
b.stmts = vec![loop_stmt];
769+
//stmt_to_block(b.rules, Some(loop_stmt), &mut self.resolver)
766770
} else {
767771
//push `loop {}` onto the end of our fresh block and yield that
768-
new_block.stmts.push(loop_stmt);
772+
stmts.push(loop_stmt);
769773

770-
new_block
774+
b.stmts = stmts;
771775
}
772-
})
776+
//})
773777
}
774778
}
775779

0 commit comments

Comments
 (0)