@@ -452,14 +452,9 @@ impl<'db> ScopeInference<'db> {
452452 self . extra . as_deref ( ) . map ( |extra| & extra. diagnostics )
453453 }
454454
455- #[ track_caller]
456455 pub ( crate ) fn expression_type ( & self , expression : impl Into < ExpressionNodeKey > ) -> Type < ' db > {
457- self . try_expression_type ( expression) . expect (
458- "Failed to retrieve the inferred type for an `ast::Expr` node \
459- passed to `TypeInference::expression_type()`. The `TypeInferenceBuilder` \
460- should infer and store types for all `ast::Expr` nodes in any `TypeInference` \
461- region it analyzes.",
462- )
456+ self . try_expression_type ( expression)
457+ . unwrap_or_else ( Type :: unknown)
463458 }
464459
465460 pub ( crate ) fn try_expression_type (
@@ -541,14 +536,9 @@ impl<'db> DefinitionInference<'db> {
541536 }
542537 }
543538
544- #[ track_caller]
545539 pub ( crate ) fn expression_type ( & self , expression : impl Into < ExpressionNodeKey > ) -> Type < ' db > {
546- self . try_expression_type ( expression) . expect (
547- "Failed to retrieve the inferred type for an `ast::Expr` node \
548- passed to `TypeInference::expression_type()`. The `TypeInferenceBuilder` \
549- should infer and store types for all `ast::Expr` nodes in any `TypeInference` \
550- region it analyzes.",
551- )
540+ self . try_expression_type ( expression)
541+ . unwrap_or_else ( Type :: unknown)
552542 }
553543
554544 pub ( crate ) fn try_expression_type (
@@ -675,14 +665,9 @@ impl<'db> ExpressionInference<'db> {
675665 . or_else ( || self . fallback_type ( ) )
676666 }
677667
678- #[ track_caller]
679668 pub ( crate ) fn expression_type ( & self , expression : impl Into < ExpressionNodeKey > ) -> Type < ' db > {
680- self . try_expression_type ( expression) . expect (
681- "Failed to retrieve the inferred type for an `ast::Expr` node \
682- passed to `TypeInference::expression_type()`. The `TypeInferenceBuilder` \
683- should infer and store types for all `ast::Expr` nodes in any `TypeInference` \
684- region it analyzes.",
685- )
669+ self . try_expression_type ( expression)
670+ . unwrap_or_else ( Type :: unknown)
686671 }
687672
688673 fn is_cycle_callback ( & self ) -> bool {
@@ -959,19 +944,9 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
959944 self . context . in_stub ( )
960945 }
961946
962- /// Get the already-inferred type of an expression node.
963- ///
964- /// ## Panics
965- /// If the expression is not within this region, or if no type has yet been inferred for
966- /// this node.
967- #[ track_caller]
947+ /// Get the already-inferred type of an expression node, or Unknown.
968948 fn expression_type ( & self , expr : & ast:: Expr ) -> Type < ' db > {
969- self . try_expression_type ( expr) . expect (
970- "Failed to retrieve the inferred type for an `ast::Expr` node \
971- passed to `TypeInference::expression_type()`. The `TypeInferenceBuilder` \
972- should infer and store types for all `ast::Expr` nodes in any `TypeInference` \
973- region it analyzes.",
974- )
949+ self . try_expression_type ( expr) . unwrap_or_else ( Type :: unknown)
975950 }
976951
977952 fn try_expression_type ( & self , expr : & ast:: Expr ) -> Option < Type < ' db > > {
0 commit comments