diff --git a/crates/ruff_python_formatter/src/comments/mod.rs b/crates/ruff_python_formatter/src/comments/mod.rs index dbb07f2dce26c..9717252a9b435 100644 --- a/crates/ruff_python_formatter/src/comments/mod.rs +++ b/crates/ruff_python_formatter/src/comments/mod.rs @@ -96,7 +96,6 @@ pub(crate) use format::{ leading_alternate_branch_comments, leading_comments, leading_node_comments, trailing_comments, }; use ruff_formatter::{SourceCode, SourceCodeSlice}; -use ruff_python_ast::visitor::preorder::{PreorderVisitor, TraversalSignal}; use ruff_python_ast::AnyNodeRef; use ruff_python_trivia::{CommentLinePosition, CommentRanges, SuppressionKind}; use ruff_source_file::Locator; @@ -407,6 +406,20 @@ impl<'a> Comments<'a> { /// normally if `node` is the first or last node of a suppression range. #[cfg(debug_assertions)] pub(crate) fn mark_verbatim_node_comments_formatted(&self, node: AnyNodeRef) { + use ruff_python_ast::visitor::preorder::{PreorderVisitor, TraversalSignal}; + + struct MarkVerbatimCommentsAsFormattedVisitor<'a>(&'a Comments<'a>); + + impl<'a> PreorderVisitor<'a> for MarkVerbatimCommentsAsFormattedVisitor<'a> { + fn enter_node(&mut self, node: AnyNodeRef<'a>) -> TraversalSignal { + for comment in self.0.leading_dangling_trailing(node) { + comment.mark_formatted(); + } + + TraversalSignal::Traverse + } + } + for dangling in self.dangling(node) { dangling.mark_formatted(); } @@ -452,18 +465,6 @@ struct CommentsData<'a> { comment_ranges: &'a CommentRanges, } -struct MarkVerbatimCommentsAsFormattedVisitor<'a>(&'a Comments<'a>); - -impl<'a> PreorderVisitor<'a> for MarkVerbatimCommentsAsFormattedVisitor<'a> { - fn enter_node(&mut self, node: AnyNodeRef<'a>) -> TraversalSignal { - for comment in self.0.leading_dangling_trailing(node) { - comment.mark_formatted(); - } - - TraversalSignal::Traverse - } -} - pub(crate) fn has_skip_comment(trailing_comments: &[SourceComment], source: &str) -> bool { trailing_comments.iter().any(|comment| { comment.line_position().is_end_of_line()