(
&mut self,
subject: Expression<'db>,
pattern: &ast::Pattern,
guard: Option<&ast::Expr>,
previous_pattern: Option<PatternPredicate<'db>>,
)
| 2787 | } |
| 2788 | |
| 2789 | fn create_pattern_predicate( |
| 2790 | &mut self, |
| 2791 | subject: Expression<'db>, |
| 2792 | pattern: &ast::Pattern, |
| 2793 | guard: Option<&ast::Expr>, |
| 2794 | previous_pattern: Option<PatternPredicate<'db>>, |
| 2795 | ) -> PatternPredicate<'db> { |
| 2796 | // This is called for the top-level pattern of each match arm. We need to create a |
| 2797 | // standalone expression for each arm of a match statement, since they can introduce |
| 2798 | // constraints on the match subject. (Or more accurately, for the match arm's pattern, |
| 2799 | // since its the pattern that introduces any constraints, not the body.) Ideally, that |
| 2800 | // standalone expression would wrap the match arm's pattern as a whole. But a standalone |
| 2801 | // expression can currently only wrap an ast::Expr, which patterns are not. So, we need to |
| 2802 | // choose an Expr that can "stand in" for the pattern, which we can wrap in a standalone |
| 2803 | // expression. |
| 2804 | // |
| 2805 | // See the comment in TypeInferenceBuilder::infer_match_pattern for more details. |
| 2806 | |
| 2807 | let kind = self.predicate_kind(pattern); |
| 2808 | let guard = |
| 2809 | guard.map(|guard| self.add_predicate_expression(guard, ExpressionContext::Condition)); |
| 2810 | |
| 2811 | PatternPredicate::new( |
| 2812 | self.db, |
| 2813 | self.file, |
| 2814 | self.current_scope(), |
| 2815 | subject, |
| 2816 | kind, |
| 2817 | guard, |
| 2818 | previous_pattern.map(Box::new), |
| 2819 | ) |
| 2820 | } |
| 2821 | |
| 2822 | fn add_pattern_narrowing_constraint( |
| 2823 | &mut self, |
no test coverage detected