@@ -452,14 +452,9 @@ impl<'db> ScopeInference<'db> {
452
452
self . extra . as_deref ( ) . map ( |extra| & extra. diagnostics )
453
453
}
454
454
455
- #[ track_caller]
456
455
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)
463
458
}
464
459
465
460
pub ( crate ) fn try_expression_type (
@@ -541,14 +536,9 @@ impl<'db> DefinitionInference<'db> {
541
536
}
542
537
}
543
538
544
- #[ track_caller]
545
539
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)
552
542
}
553
543
554
544
pub ( crate ) fn try_expression_type (
@@ -675,14 +665,9 @@ impl<'db> ExpressionInference<'db> {
675
665
. or_else ( || self . fallback_type ( ) )
676
666
}
677
667
678
- #[ track_caller]
679
668
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)
686
671
}
687
672
688
673
fn is_cycle_callback ( & self ) -> bool {
@@ -959,19 +944,9 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
959
944
self . context . in_stub ( )
960
945
}
961
946
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.
968
948
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)
975
950
}
976
951
977
952
fn try_expression_type ( & self , expr : & ast:: Expr ) -> Option < Type < ' db > > {
0 commit comments