mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-09 13:18:52 +00:00
Remove Statements#parent
(#6392)
Discussed in https://github.com/astral-sh/ruff/pull/6351#discussion_r1284997065.
This commit is contained in:
parent
e4a4660925
commit
9328606843
6 changed files with 12 additions and 17 deletions
|
@ -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`].
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue