Skip to content

Commit 7d43f33

Browse files
Panic if a match has reached a too big complexity
1 parent 4857a31 commit 7d43f33

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

compiler/rustc_pattern_analysis/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ pub trait TypeCx: Sized + fmt::Debug {
145145

146146
/// The maximum pattern complexity limit was reached.
147147
fn complexity_exceeded(&self) -> Result<(), Self::Error>;
148+
149+
fn too_complex_match(&self);
148150
}
149151

150152
/// The arm of a match expression.

compiler/rustc_pattern_analysis/src/rustc.rs

+4
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,10 @@ impl<'p, 'tcx: 'p> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
900900
let span = self.whole_match_span.unwrap_or(self.scrut_span);
901901
Err(self.tcx.dcx().span_err(span, "reached pattern complexity limit"))
902902
}
903+
904+
fn too_complex_match(&self) {
905+
panic!("match too complex!");
906+
}
903907
}
904908

905909
/// Recursively expand this pattern into its subpatterns. Only useful for or-patterns.

compiler/rustc_pattern_analysis/src/usefulness.rs

+4
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,10 @@ impl<'a, Cx: TypeCx> UsefulnessCtxt<'a, Cx> {
747747
{
748748
return self.tycx.complexity_exceeded();
749749
}
750+
// FIXME: Will be turned into a warning once we have a somewhat useable threeshold.
751+
if self.complexity_level > 10_000_000 {
752+
self.tycx.too_complex_match();
753+
}
750754
Ok(())
751755
}
752756
}

0 commit comments

Comments
 (0)