Skip to content

Commit

Permalink
Fix 'MarkVerbatimCommentsAsFormattedVisitor' is unused warning in rel…
Browse files Browse the repository at this point in the history
…ease builds (#11304)
  • Loading branch information
MichaReiser authored May 6, 2024
1 parent 1bb61ba commit 868bbd4
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions crates/ruff_python_formatter/src/comments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 868bbd4

Please sign in to comment.