Auto merge of #12634 - iDawer:match-check.witnesses, r=flodiebold

feat: Show witnesses of non-exhaustiveness in `missing-match-arm` diagnostic

Shamelessly copied from rustc. Thus reporting format is same.

This extends public api  `hir::diagnostics::MissingMatchArms` with `uncovered_patterns: String` field. It does not expose data for implementing a quick fix yet.

-----
Worth to note: current implementation does not give a comprehensive list of missing patterns. Also mentioned in [paper](http://moscova.inria.fr/~maranget/papers/warn/warn.pdf):

> One may think that algorithm I should make an additional effort to provide more
> non-matching values, by systematically computing recursive calls on specialized
> matrices when possible, and by returning a list of all pattern vectors returned by
> recursive calls. We can first observe that it is not possible in general to supply the
> users with all non-matching values, since the signature of integers is (potentially)
> infinite.
This commit is contained in:
bors 2022-06-30 14:51:58 +00:00
commit 642084093a
6 changed files with 330 additions and 93 deletions

View file

@ -1312,7 +1312,7 @@ impl DefWithBody {
);
}
}
BodyValidationDiagnostic::MissingMatchArms { match_expr } => {
BodyValidationDiagnostic::MissingMatchArms { match_expr, uncovered_patterns } => {
match source_map.expr_syntax(match_expr) {
Ok(source_ptr) => {
let root = source_ptr.file_syntax(db.upcast());
@ -1324,6 +1324,7 @@ impl DefWithBody {
MissingMatchArms {
file: source_ptr.file_id,
match_expr: AstPtr::new(&match_expr),
uncovered_patterns,
}
.into(),
);