[ty] Avoid second lookup for infer_maybe_standalone_expression (#19439)

This commit is contained in:
Micha Reiser
2025-07-20 18:22:04 +02:00
committed by GitHub
parent 0acc273286
commit 84e76f4d04

View File

@@ -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);