about summary refs log tree commit diff
path: root/compiler/rustc_ast/src
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2024-12-02 18:38:45 -0800
committerDavid Tolnay <dtolnay@gmail.com>2024-12-03 07:03:26 -0800
commita3cfe2fd083408b53fa02a90af718b49d2bbe83a (patch)
treeac7c3dcf0a04007969dafdada8edf8078ba52194 /compiler/rustc_ast/src
parenta2eca35c15a1d594dea89543baa38499249f50ee (diff)
downloadrust-a3cfe2fd083408b53fa02a90af718b49d2bbe83a.tar.gz
rust-a3cfe2fd083408b53fa02a90af718b49d2bbe83a.zip
Visit Stmt span in MutVisitor::flat_map_stmt
Diffstat (limited to 'compiler/rustc_ast/src')
-rw-r--r--compiler/rustc_ast/src/mut_visit.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs
index 1e02dc8fb24..0c2fe61a698 100644
--- a/compiler/rustc_ast/src/mut_visit.rs
+++ b/compiler/rustc_ast/src/mut_visit.rs
@@ -1789,20 +1789,21 @@ pub fn noop_filter_map_expr<T: MutVisitor>(vis: &mut T, mut e: P<Expr>) -> Optio
 
 pub fn walk_flat_map_stmt<T: MutVisitor>(
     vis: &mut T,
-    Stmt { kind, mut span, mut id }: Stmt,
+    Stmt { kind, span, mut id }: Stmt,
 ) -> SmallVec<[Stmt; 1]> {
     vis.visit_id(&mut id);
-    let stmts: SmallVec<_> = walk_flat_map_stmt_kind(vis, kind)
+    let mut stmts: SmallVec<[Stmt; 1]> = walk_flat_map_stmt_kind(vis, kind)
         .into_iter()
         .map(|kind| Stmt { id, kind, span })
         .collect();
-    if stmts.len() > 1 {
-        panic!(
+    match stmts.len() {
+        0 => {}
+        1 => vis.visit_span(&mut stmts[0].span),
+        2.. => panic!(
             "cloning statement `NodeId`s is prohibited by default, \
              the visitor should implement custom statement visiting"
-        );
+        ),
     }
-    vis.visit_span(&mut span);
     stmts
 }