diff --git a/crates/red_knot_python_semantic/src/semantic_index/definition.rs b/crates/red_knot_python_semantic/src/semantic_index/definition.rs index d39c918a82..fc75d252da 100644 --- a/crates/red_knot_python_semantic/src/semantic_index/definition.rs +++ b/crates/red_knot_python_semantic/src/semantic_index/definition.rs @@ -473,8 +473,14 @@ pub enum DefinitionKind<'db> { TypeVarTuple(AstNodeRef), } -impl Ranged for DefinitionKind<'_> { - fn range(&self) -> TextRange { +impl DefinitionKind<'_> { + /// Returns the [`TextRange`] of the definition target. + /// + /// A definition target would mainly be the node representing the symbol being defined i.e., + /// [`ast::ExprName`] or [`ast::Identifier`] but could also be other nodes. + /// + /// This is mainly used for logging and debugging purposes. + pub(crate) fn target_range(&self) -> TextRange { match self { DefinitionKind::Import(alias) => alias.range(), DefinitionKind::ImportFrom(import) => import.alias().range(), @@ -498,9 +504,7 @@ impl Ranged for DefinitionKind<'_> { DefinitionKind::TypeVarTuple(type_var_tuple) => type_var_tuple.name.range(), } } -} -impl DefinitionKind<'_> { pub(crate) fn category(&self) -> DefinitionCategory { match self { // functions, classes, and imports always bind, and we consider them declarations diff --git a/crates/red_knot_python_semantic/src/types/infer.rs b/crates/red_knot_python_semantic/src/types/infer.rs index 6111eaf72f..23885f3a12 100644 --- a/crates/red_knot_python_semantic/src/types/infer.rs +++ b/crates/red_knot_python_semantic/src/types/infer.rs @@ -131,7 +131,7 @@ pub(crate) fn infer_definition_types<'db>( let file = definition.file(db); let _span = tracing::trace_span!( "infer_definition_types", - range = ?definition.kind(db).range(), + range = ?definition.kind(db).target_range(), file = %file.path(db) ) .entered(); @@ -154,7 +154,7 @@ pub(crate) fn infer_deferred_types<'db>( let _span = tracing::trace_span!( "infer_deferred_types", definition = ?definition.as_id(), - range = ?definition.kind(db).range(), + range = ?definition.kind(db).target_range(), file = %file.path(db) ) .entered();