Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/ruff_python_ast/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,8 @@ def write_anynoderef(out: list[str], ast: Ast) -> None:

out.append("""
impl ruff_text_size::Ranged for AnyNodeRef<'_> {
#[expect(clippy::inline_always, reason = "enables constant-folding for known `AnyNodeRef` variants")]
#[inline(always)]
fn range(&self) -> ruff_text_size::TextRange {
match self {
""")
Expand Down
5 changes: 5 additions & 0 deletions crates/ruff_python_ast/src/generated.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions crates/ruff_python_formatter/src/comments/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ impl<'a, 'builder> CommentsVisitor<'a, 'builder> {
}

impl<'ast> SourceOrderVisitor<'ast> for CommentsVisitor<'ast, '_> {
#[expect(
clippy::inline_always,
reason = "enables constant-folding of `AnyNodeRef` helpers"
)]
#[inline(always)]
fn enter_node(&mut self, node: AnyNodeRef<'ast>) -> TraversalSignal {
let node_range = node.range();

Expand Down Expand Up @@ -111,6 +116,11 @@ impl<'ast> SourceOrderVisitor<'ast> for CommentsVisitor<'ast, '_> {
}
}

#[expect(
clippy::inline_always,
reason = "enables constant-folding of `AnyNodeRef` helpers"
)]
#[inline(always)]
fn leave_node(&mut self, node: AnyNodeRef<'ast>) {
// We are leaving this node, pop it from the parent stack.
self.parents.pop();
Expand Down Expand Up @@ -147,6 +157,11 @@ impl<'ast> SourceOrderVisitor<'ast> for CommentsVisitor<'ast, '_> {
self.preceding_node = Some(node);
}

#[expect(
clippy::inline_always,
reason = "enables constant-folding of `AnyNodeRef` helpers"
)]
#[inline(always)]
fn visit_body(&mut self, body: &'ast [Stmt]) {
match body {
[] => {
Expand Down
Loading