From 8b6e4d3f6cba3217c76ac9ad6449a860a65b8de0 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Sun, 20 Jul 2025 18:07:49 +0200 Subject: [PATCH] [ty] Avoid second lookup for `infer_maybe_standalone_expression --- crates/ty_python_semantic/src/types/infer.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index c0f31985f3017..ba9df15c14eec 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -4860,15 +4860,24 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } fn infer_maybe_standalone_expression(&mut self, expression: &ast::Expr) -> Type<'db> { - if self.index.is_standalone_expression(expression) { - self.infer_standalone_expression(expression) + if let Some(standalone_expression) = self.index.try_expression(expression) { + self.infer_standalone_expression_impl(expression, standalone_expression) } else { self.infer_expression(expression) } } + #[track_caller] fn infer_standalone_expression(&mut self, expression: &ast::Expr) -> Type<'db> { let standalone_expression = self.index.expression(expression); + self.infer_standalone_expression_impl(expression, standalone_expression) + } + + fn infer_standalone_expression_impl( + &mut self, + expression: &ast::Expr, + standalone_expression: Expression<'db>, + ) -> Type<'db> { let types = infer_expression_types(self.db(), standalone_expression); self.extend(types);