Skip to content

Commit 3691a0a

Browse files
committed
Gather rustc-specific functions around MatchCheckCtxt
1 parent 281002d commit 3691a0a

File tree

8 files changed

+903
-900
lines changed

8 files changed

+903
-900
lines changed

compiler/rustc_mir_build/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::{
66
};
77
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
88
use rustc_middle::ty::{self, Ty};
9-
use rustc_pattern_analysis::{errors::Uncovered, usefulness::MatchCheckCtxt};
9+
use rustc_pattern_analysis::{cx::MatchCheckCtxt, errors::Uncovered};
1010
use rustc_span::symbol::Symbol;
1111
use rustc_span::Span;
1212

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use rustc_pattern_analysis::constructor::Constructor;
2+
use rustc_pattern_analysis::cx::MatchCheckCtxt;
23
use rustc_pattern_analysis::errors::Uncovered;
34
use rustc_pattern_analysis::pat::{DeconstructedPat, WitnessPat};
45
use rustc_pattern_analysis::usefulness::{
5-
compute_match_usefulness, MatchArm, MatchCheckCtxt, Usefulness, UsefulnessReport,
6+
compute_match_usefulness, MatchArm, Usefulness, UsefulnessReport,
67
};
78

89
use crate::errors::*;
@@ -286,7 +287,7 @@ impl<'thir, 'p, 'tcx> MatchVisitor<'thir, 'p, 'tcx> {
286287
check_borrow_conflicts_in_at_patterns(self, pat);
287288
check_for_bindings_named_same_as_variants(self, pat, refutable);
288289
});
289-
Ok(cx.pattern_arena.alloc(DeconstructedPat::from_pat(cx, pat)))
290+
Ok(cx.pattern_arena.alloc(cx.lower_pat(pat)))
290291
}
291292
}
292293

@@ -926,7 +927,7 @@ fn report_non_exhaustive_match<'p, 'tcx>(
926927
pattern = if witnesses.len() < 4 {
927928
witnesses
928929
.iter()
929-
.map(|witness| witness.to_diagnostic_pat(cx).to_string())
930+
.map(|witness| cx.hoist_witness_pat(witness).to_string())
930931
.collect::<Vec<String>>()
931932
.join(" | ")
932933
} else {
@@ -950,7 +951,7 @@ fn report_non_exhaustive_match<'p, 'tcx>(
950951
if !is_empty_match {
951952
let mut non_exhaustive_tys = FxHashSet::default();
952953
// Look at the first witness.
953-
collect_non_exhaustive_tys(cx.tcx, &witnesses[0], &mut non_exhaustive_tys);
954+
collect_non_exhaustive_tys(cx, &witnesses[0], &mut non_exhaustive_tys);
954955

955956
for ty in non_exhaustive_tys {
956957
if ty.is_ptr_sized_integral() {
@@ -1085,13 +1086,13 @@ fn joined_uncovered_patterns<'p, 'tcx>(
10851086
witnesses: &[WitnessPat<'tcx>],
10861087
) -> String {
10871088
const LIMIT: usize = 3;
1088-
let pat_to_str = |pat: &WitnessPat<'tcx>| pat.to_diagnostic_pat(cx).to_string();
1089+
let pat_to_str = |pat: &WitnessPat<'tcx>| cx.hoist_witness_pat(pat).to_string();
10891090
match witnesses {
10901091
[] => bug!(),
1091-
[witness] => format!("`{}`", witness.to_diagnostic_pat(cx)),
1092+
[witness] => format!("`{}`", cx.hoist_witness_pat(witness)),
10921093
[head @ .., tail] if head.len() < LIMIT => {
10931094
let head: Vec<_> = head.iter().map(pat_to_str).collect();
1094-
format!("`{}` and `{}`", head.join("`, `"), tail.to_diagnostic_pat(cx))
1095+
format!("`{}` and `{}`", head.join("`, `"), cx.hoist_witness_pat(tail))
10951096
}
10961097
_ => {
10971098
let (head, tail) = witnesses.split_at(LIMIT);
@@ -1102,21 +1103,21 @@ fn joined_uncovered_patterns<'p, 'tcx>(
11021103
}
11031104

11041105
fn collect_non_exhaustive_tys<'tcx>(
1105-
tcx: TyCtxt<'tcx>,
1106+
cx: &MatchCheckCtxt<'_, 'tcx>,
11061107
pat: &WitnessPat<'tcx>,
11071108
non_exhaustive_tys: &mut FxHashSet<Ty<'tcx>>,
11081109
) {
11091110
if matches!(pat.ctor(), Constructor::NonExhaustive) {
11101111
non_exhaustive_tys.insert(pat.ty());
11111112
}
11121113
if let Constructor::IntRange(range) = pat.ctor() {
1113-
if range.is_beyond_boundaries(pat.ty(), tcx) {
1114+
if cx.is_range_beyond_boundaries(range, pat.ty()) {
11141115
// The range denotes the values before `isize::MIN` or the values after `usize::MAX`/`isize::MAX`.
11151116
non_exhaustive_tys.insert(pat.ty());
11161117
}
11171118
}
11181119
pat.iter_fields()
1119-
.for_each(|field_pat| collect_non_exhaustive_tys(tcx, field_pat, non_exhaustive_tys))
1120+
.for_each(|field_pat| collect_non_exhaustive_tys(cx, field_pat, non_exhaustive_tys))
11201121
}
11211122

11221123
fn report_adt_defined_here<'tcx>(

0 commit comments

Comments
 (0)