1
Fork 0

Add new pattern_complexity attribute to add possibility to limit and check recursion in pattern matching

This commit is contained in:
Guillaume Gomez 2024-03-02 22:48:41 +01:00
parent 5257aee7dd
commit be31b6b6cd
8 changed files with 56 additions and 6 deletions

View file

@ -895,6 +895,11 @@ impl<'p, 'tcx: 'p> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
errors::OverlappingRangeEndpoints { overlap: overlaps, range: pat_span },
);
}
fn complexity_exceeded(&self) -> Result<(), Self::Error> {
let span = self.whole_match_span.unwrap_or(self.scrut_span);
Err(self.tcx.dcx().span_err(span, "reached pattern complexity limit"))
}
}
/// Recursively expand this pattern into its subpatterns. Only useful for or-patterns.