diff --git a/crates/ruff_python_semantic/src/definition.rs b/crates/ruff_python_semantic/src/definition.rs index df75490f5e..6d73624a66 100644 --- a/crates/ruff_python_semantic/src/definition.rs +++ b/crates/ruff_python_semantic/src/definition.rs @@ -115,7 +115,7 @@ impl<'a> Definitions<'a> { /// /// Members are assumed to be pushed in traversal order, such that parents are pushed before /// their children. - pub fn push_member(&mut self, member: Member<'a>) -> DefinitionId { + pub(crate) fn push_member(&mut self, member: Member<'a>) -> DefinitionId { self.0.push(Definition::Member(member)) } diff --git a/crates/ruff_python_semantic/src/globals.rs b/crates/ruff_python_semantic/src/globals.rs index dd4b2c460a..876ecfb628 100644 --- a/crates/ruff_python_semantic/src/globals.rs +++ b/crates/ruff_python_semantic/src/globals.rs @@ -49,11 +49,11 @@ impl<'a> Globals<'a> { builder.finish() } - pub fn get(&self, name: &str) -> Option<&TextRange> { + pub(crate) fn get(&self, name: &str) -> Option<&TextRange> { self.0.get(name) } - pub fn iter(&self) -> impl Iterator + '_ { + pub(crate) fn iter(&self) -> impl Iterator + '_ { self.0.iter() } } diff --git a/crates/ruff_python_semantic/src/node.rs b/crates/ruff_python_semantic/src/node.rs index dd71fd5f1d..6cdafd55b4 100644 --- a/crates/ruff_python_semantic/src/node.rs +++ b/crates/ruff_python_semantic/src/node.rs @@ -37,7 +37,7 @@ impl<'a> Nodes<'a> { /// Inserts a new node into the node tree and returns its unique id. /// /// Panics if a node with the same pointer already exists. - pub fn insert(&mut self, stmt: &'a Stmt, parent: Option) -> NodeId { + pub(crate) fn insert(&mut self, stmt: &'a Stmt, parent: Option) -> NodeId { let next_id = self.nodes.next_index(); if let Some(existing_id) = self.node_to_id.insert(RefEquality(stmt), next_id) { panic!("Node already exists with id {existing_id:?}"); @@ -61,23 +61,23 @@ impl<'a> Nodes<'a> { self.nodes[node_id].parent } - /// Return the depth of the node. - #[inline] - pub fn depth(&self, node_id: NodeId) -> u32 { - self.nodes[node_id].depth - } - - /// Returns an iterator over all [`NodeId`] ancestors, starting from the given [`NodeId`]. - pub fn ancestor_ids(&self, node_id: NodeId) -> impl Iterator + '_ { - std::iter::successors(Some(node_id), |&node_id| self.nodes[node_id].parent) - } - /// Return the parent of the given node. pub fn parent(&self, node: &'a Stmt) -> Option<&'a Stmt> { let node_id = self.node_to_id.get(&RefEquality(node))?; let parent_id = self.nodes[*node_id].parent?; Some(self[parent_id]) } + + /// Return the depth of the node. + #[inline] + pub(crate) fn depth(&self, node_id: NodeId) -> u32 { + self.nodes[node_id].depth + } + + /// Returns an iterator over all [`NodeId`] ancestors, starting from the given [`NodeId`]. + pub(crate) fn ancestor_ids(&self, node_id: NodeId) -> impl Iterator + '_ { + std::iter::successors(Some(node_id), |&node_id| self.nodes[node_id].parent) + } } impl<'a> Index for Nodes<'a> { diff --git a/crates/ruff_python_semantic/src/reference.rs b/crates/ruff_python_semantic/src/reference.rs index 0626a5c808..d19b03194a 100644 --- a/crates/ruff_python_semantic/src/reference.rs +++ b/crates/ruff_python_semantic/src/reference.rs @@ -36,11 +36,11 @@ pub struct ReferenceId; /// The references of a program indexed by [`ReferenceId`]. #[derive(Debug, Default)] -pub struct References(IndexVec); +pub(crate) struct References(IndexVec); impl References { /// Pushes a new [`Reference`] and returns its [`ReferenceId`]. - pub fn push( + pub(crate) fn push( &mut self, scope_id: ScopeId, range: TextRange, diff --git a/crates/ruff_python_semantic/src/scope.rs b/crates/ruff_python_semantic/src/scope.rs index 22f0983915..e5100b3859 100644 --- a/crates/ruff_python_semantic/src/scope.rs +++ b/crates/ruff_python_semantic/src/scope.rs @@ -124,12 +124,12 @@ impl<'a> Scope<'a> { } /// Set the globals pointer for this scope. - pub fn set_globals_id(&mut self, globals: GlobalsId) { + pub(crate) fn set_globals_id(&mut self, globals: GlobalsId) { self.globals_id = Some(globals); } /// Returns the globals pointer for this scope. - pub fn globals_id(&self) -> Option { + pub(crate) fn globals_id(&self) -> Option { self.globals_id } @@ -196,17 +196,17 @@ pub struct Scopes<'a>(IndexVec>); impl<'a> Scopes<'a> { /// Returns a reference to the global scope - pub fn global(&self) -> &Scope<'a> { + pub(crate) fn global(&self) -> &Scope<'a> { &self[ScopeId::global()] } /// Returns a mutable reference to the global scope - pub fn global_mut(&mut self) -> &mut Scope<'a> { + pub(crate) fn global_mut(&mut self) -> &mut Scope<'a> { &mut self[ScopeId::global()] } /// Pushes a new scope and returns its unique id - pub fn push_scope(&mut self, kind: ScopeKind<'a>, parent: ScopeId) -> ScopeId { + pub(crate) fn push_scope(&mut self, kind: ScopeKind<'a>, parent: ScopeId) -> ScopeId { let next_id = ScopeId::new(self.0.len()); self.0.push(Scope::local(kind, parent)); next_id