Skip to content

Commit a3cfe2f

Browse files
committed
Visit Stmt span in MutVisitor::flat_map_stmt
1 parent a2eca35 commit a3cfe2f

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

compiler/rustc_ast/src/mut_visit.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1789,20 +1789,21 @@ pub fn noop_filter_map_expr<T: MutVisitor>(vis: &mut T, mut e: P<Expr>) -> Optio
17891789

17901790
pub fn walk_flat_map_stmt<T: MutVisitor>(
17911791
vis: &mut T,
1792-
Stmt { kind, mut span, mut id }: Stmt,
1792+
Stmt { kind, span, mut id }: Stmt,
17931793
) -> SmallVec<[Stmt; 1]> {
17941794
vis.visit_id(&mut id);
1795-
let stmts: SmallVec<_> = walk_flat_map_stmt_kind(vis, kind)
1795+
let mut stmts: SmallVec<[Stmt; 1]> = walk_flat_map_stmt_kind(vis, kind)
17961796
.into_iter()
17971797
.map(|kind| Stmt { id, kind, span })
17981798
.collect();
1799-
if stmts.len() > 1 {
1800-
panic!(
1799+
match stmts.len() {
1800+
0 => {}
1801+
1 => vis.visit_span(&mut stmts[0].span),
1802+
2.. => panic!(
18011803
"cloning statement `NodeId`s is prohibited by default, \
18021804
the visitor should implement custom statement visiting"
1803-
);
1805+
),
18041806
}
1805-
vis.visit_span(&mut span);
18061807
stmts
18071808
}
18081809

tests/ui-fulldeps/pprust-parenthesis-insertion.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ extern crate rustc_errors;
3636
extern crate rustc_parse;
3737
extern crate rustc_session;
3838
extern crate rustc_span;
39-
extern crate smallvec;
4039

4140
use std::mem;
4241
use std::process::ExitCode;
4342

44-
use rustc_ast::ast::{DUMMY_NODE_ID, Expr, ExprKind, Stmt};
43+
use rustc_ast::ast::{DUMMY_NODE_ID, Expr, ExprKind};
4544
use rustc_ast::mut_visit::{self, DummyAstNode as _, MutVisitor};
4645
use rustc_ast::node_id::NodeId;
4746
use rustc_ast::ptr::P;
@@ -50,7 +49,6 @@ use rustc_errors::Diag;
5049
use rustc_parse::parser::Recovery;
5150
use rustc_session::parse::ParseSess;
5251
use rustc_span::{DUMMY_SP, FileName, Span};
53-
use smallvec::SmallVec;
5452

5553
// Every parenthesis in the following expressions is re-inserted by the
5654
// pretty-printer.
@@ -164,11 +162,6 @@ impl MutVisitor for Normalize {
164162
fn visit_span(&mut self, span: &mut Span) {
165163
*span = DUMMY_SP;
166164
}
167-
168-
fn flat_map_stmt(&mut self, mut stmt: Stmt) -> SmallVec<[Stmt; 1]> {
169-
self.visit_span(&mut stmt.span);
170-
mut_visit::walk_flat_map_stmt(self, stmt)
171-
}
172165
}
173166

174167
fn parse_expr(psess: &ParseSess, source_code: &str) -> Option<P<Expr>> {

0 commit comments

Comments
 (0)