Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] crater: emit a warning if a match is too complex #121979

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_pattern_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ pub trait TypeCx: Sized + fmt::Debug {

/// The maximum pattern complexity limit was reached.
fn complexity_exceeded(&self) -> Result<(), Self::Error>;

fn too_complex_match(&self);
}

/// The arm of a match expression.
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_pattern_analysis/src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,10 @@ impl<'p, 'tcx: 'p> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
let span = self.whole_match_span.unwrap_or(self.scrut_span);
Err(self.tcx.dcx().span_err(span, "reached pattern complexity limit"))
}

fn too_complex_match(&self) {
panic!("match too complex!");
}
}

/// Recursively expand this pattern into its subpatterns. Only useful for or-patterns.
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_pattern_analysis/src/usefulness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,10 @@ impl<'a, Cx: TypeCx> UsefulnessCtxt<'a, Cx> {
{
return self.tycx.complexity_exceeded();
}
// FIXME: Will be turned into a warning once we have a somewhat useable threeshold.
if self.complexity_level > 10_000_000 {
self.tycx.too_complex_match();
}
Ok(())
}
}
Expand Down
106 changes: 0 additions & 106 deletions tests/ui/pattern/complexity_limit.rs

This file was deleted.

14 changes: 0 additions & 14 deletions tests/ui/pattern/complexity_limit.stderr

This file was deleted.

Loading