mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-16 08:30:30 +00:00
Remove AstNode
and AnyNode
(#15479)
While looking into potential AST optimizations, I noticed the `AstNode` trait and `AnyNode` type aren't used anywhere in Ruff or Red Knot. It looks like they might be historical artifacts of previous ways of consuming AST nodes? - `AstNode::cast`, `AstNode::cast_ref`, and `AstNode::can_cast` are not used anywhere. - Since `cast_ref` isn't needed anymore, the `Ref` associated type isn't either. This is a pure refactoring, with no intended behavior changes.
This commit is contained in:
parent
8e3633f55a
commit
98ef564170
24 changed files with 52 additions and 5349 deletions
|
@ -1,26 +1,8 @@
|
|||
use crate::visitor::source_order::SourceOrderVisitor;
|
||||
use crate::{
|
||||
self as ast, Alias, AnyNode, AnyNodeRef, AnyParameterRef, ArgOrKeyword, MatchCase, NodeKind,
|
||||
PatternArguments, PatternKeyword,
|
||||
self as ast, Alias, AnyNodeRef, AnyParameterRef, ArgOrKeyword, MatchCase, PatternArguments,
|
||||
PatternKeyword,
|
||||
};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
pub trait AstNode: Ranged {
|
||||
type Ref<'a>;
|
||||
|
||||
fn cast(kind: AnyNode) -> Option<Self>
|
||||
where
|
||||
Self: Sized;
|
||||
fn cast_ref(kind: AnyNodeRef<'_>) -> Option<Self::Ref<'_>>;
|
||||
|
||||
fn can_cast(kind: NodeKind) -> bool;
|
||||
|
||||
/// Returns the [`AnyNodeRef`] referencing this node.
|
||||
fn as_any_node_ref(&self) -> AnyNodeRef;
|
||||
|
||||
/// Consumes `self` and returns its [`AnyNode`] representation.
|
||||
fn into_any_node(self) -> AnyNode;
|
||||
}
|
||||
|
||||
impl ast::ModModule {
|
||||
pub(crate) fn visit_source_order<'a, V>(&'a self, visitor: &mut V)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue