Remove Statements#parent (#6392)

Discussed in
https://github.com/astral-sh/ruff/pull/6351#discussion_r1284997065.
This commit is contained in:
Charlie Marsh 2023-08-07 11:41:02 -04:00 committed by GitHub
parent e4a4660925
commit 9328606843
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 17 deletions

View file

@ -940,8 +940,10 @@ impl<'a> SemanticModel<'a> {
/// Given a [`Stmt`], return its parent, if any.
#[inline]
pub fn parent_statement(&self, statement: &'a Stmt) -> Option<&'a Stmt> {
self.statements.parent(statement)
pub fn parent_statement(&self, statement_id: StatementId) -> Option<&'a Stmt> {
self.statements
.parent_id(statement_id)
.map(|id| self.statements[id])
}
/// Set the [`Globals`] for the current [`Scope`].

View file

@ -1,10 +1,10 @@
use std::ops::Index;
use ruff_index::{newtype_index, IndexVec};
use ruff_python_ast::Stmt;
use rustc_hash::FxHashMap;
use ruff_index::{newtype_index, IndexVec};
use ruff_python_ast::types::RefEquality;
use ruff_python_ast::Stmt;
/// Id uniquely identifying a statement AST node.
///
@ -65,13 +65,6 @@ impl<'a> Statements<'a> {
self.statements[statement_id].parent
}
/// Return the parent of the given statement.
pub fn parent(&self, statement: &'a Stmt) -> Option<&'a Stmt> {
let statement_id = self.statement_to_id.get(&RefEquality(statement))?;
let parent_id = self.statements[*statement_id].parent?;
Some(self[parent_id])
}
/// Return the depth of the statement.
#[inline]
pub(crate) fn depth(&self, id: StatementId) -> u32 {