Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ddfcc17

Browse files
committed
pcx.span was no longer meaningful
1 parent 702d104 commit ddfcc17

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ impl<'tcx> Constructor<'tcx> {
723723
/// this checks for inclusion.
724724
// We inline because this has a single call site in `Matrix::specialize_constructor`.
725725
#[inline]
726-
pub(super) fn is_covered_by<'p>(&self, pcx: &PatCtxt<'_, 'p, 'tcx>, other: &Self) -> bool {
726+
pub(super) fn is_covered_by(&self, other: &Self) -> bool {
727727
// This must be compatible with `ConstructorSet::split`.
728728
match (self, other) {
729729
// Wildcards cover anything
@@ -763,12 +763,7 @@ impl<'tcx> Constructor<'tcx> {
763763
(Opaque(self_id), Opaque(other_id)) => self_id == other_id,
764764
(Opaque(..), _) | (_, Opaque(..)) => false,
765765

766-
_ => span_bug!(
767-
pcx.span,
768-
"trying to compare incompatible constructors {:?} and {:?}",
769-
self,
770-
other
771-
),
766+
_ => bug!("trying to compare incompatible constructors {:?} and {:?}", self, other),
772767
}
773768
}
774769
}
@@ -1134,9 +1129,8 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
11341129
fn wildcards_from_tys(
11351130
cx: &MatchCheckCtxt<'p, 'tcx>,
11361131
tys: impl IntoIterator<Item = Ty<'tcx>>,
1137-
span: Span,
11381132
) -> Self {
1139-
Fields::from_iter(cx, tys.into_iter().map(|ty| DeconstructedPat::wildcard(ty, span)))
1133+
Fields::from_iter(cx, tys.into_iter().map(|ty| DeconstructedPat::wildcard(ty, DUMMY_SP)))
11401134
}
11411135

11421136
// In the cases of either a `#[non_exhaustive]` field list or a non-public field, we hide
@@ -1172,26 +1166,26 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
11721166
pub(super) fn wildcards(pcx: &PatCtxt<'_, 'p, 'tcx>, constructor: &Constructor<'tcx>) -> Self {
11731167
let ret = match constructor {
11741168
Single | Variant(_) => match pcx.ty.kind() {
1175-
ty::Tuple(fs) => Fields::wildcards_from_tys(pcx.cx, fs.iter(), pcx.span),
1176-
ty::Ref(_, rty, _) => Fields::wildcards_from_tys(pcx.cx, once(*rty), pcx.span),
1169+
ty::Tuple(fs) => Fields::wildcards_from_tys(pcx.cx, fs.iter()),
1170+
ty::Ref(_, rty, _) => Fields::wildcards_from_tys(pcx.cx, once(*rty)),
11771171
ty::Adt(adt, args) => {
11781172
if adt.is_box() {
11791173
// The only legal patterns of type `Box` (outside `std`) are `_` and box
11801174
// patterns. If we're here we can assume this is a box pattern.
1181-
Fields::wildcards_from_tys(pcx.cx, once(args.type_at(0)), pcx.span)
1175+
Fields::wildcards_from_tys(pcx.cx, once(args.type_at(0)))
11821176
} else {
11831177
let variant = &adt.variant(constructor.variant_index_for_adt(*adt));
11841178
let tys = Fields::list_variant_nonhidden_fields(pcx.cx, pcx.ty, variant)
11851179
.map(|(_, ty)| ty);
1186-
Fields::wildcards_from_tys(pcx.cx, tys, pcx.span)
1180+
Fields::wildcards_from_tys(pcx.cx, tys)
11871181
}
11881182
}
11891183
_ => bug!("Unexpected type for `Single` constructor: {:?}", pcx),
11901184
},
11911185
Slice(slice) => match *pcx.ty.kind() {
11921186
ty::Slice(ty) | ty::Array(ty, _) => {
11931187
let arity = slice.arity();
1194-
Fields::wildcards_from_tys(pcx.cx, (0..arity).map(|_| ty), pcx.span)
1188+
Fields::wildcards_from_tys(pcx.cx, (0..arity).map(|_| ty))
11951189
}
11961190
_ => bug!("bad slice pattern {:?} {:?}", constructor, pcx),
11971191
},
@@ -1488,7 +1482,7 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
14881482
let wildcard: &_ = pcx
14891483
.cx
14901484
.pattern_arena
1491-
.alloc(DeconstructedPat::wildcard(inner_ty, pcx.span));
1485+
.alloc(DeconstructedPat::wildcard(inner_ty, DUMMY_SP));
14921486
let extra_wildcards = other_slice.arity() - self_slice.arity();
14931487
let extra_wildcards = (0..extra_wildcards).map(|_| wildcard);
14941488
prefix.iter().chain(extra_wildcards).chain(suffix).collect()

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,6 @@ pub(super) struct PatCtxt<'a, 'p, 'tcx> {
360360
pub(super) cx: &'a MatchCheckCtxt<'p, 'tcx>,
361361
/// Type of the current column under investigation.
362362
pub(super) ty: Ty<'tcx>,
363-
/// Span of the current pattern under investigation.
364-
pub(super) span: Span,
365363
}
366364

367365
impl<'a, 'p, 'tcx> fmt::Debug for PatCtxt<'a, 'p, 'tcx> {
@@ -532,7 +530,7 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
532530
let mut matrix =
533531
Matrix::empty(self.wildcard_row.pop_head_constructor(pcx, ctor, usize::MAX));
534532
for (i, row) in self.rows().enumerate() {
535-
if ctor.is_covered_by(pcx, row.head().ctor()) {
533+
if ctor.is_covered_by(row.head().ctor()) {
536534
let new_row = row.pop_head_constructor(pcx, ctor, i);
537535
matrix.push(new_row);
538536
}
@@ -788,7 +786,7 @@ fn compute_usefulness<'p, 'tcx>(
788786

789787
let ty = matrix.head_ty();
790788
debug!("ty: {ty:?}");
791-
let pcx = &PatCtxt { cx, ty, span: DUMMY_SP };
789+
let pcx = &PatCtxt { cx, ty };
792790

793791
let ctors = matrix.heads().map(|p| p.ctor());
794792
let split_set = ConstructorSet::for_ty(pcx.cx, pcx.ty).split(pcx, ctors, is_top_level);
@@ -915,7 +913,7 @@ fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
915913
column: &[&DeconstructedPat<'p, 'tcx>],
916914
) -> Vec<WitnessPat<'tcx>> {
917915
let ty = column[0].ty();
918-
let pcx = &PatCtxt { cx, ty, span: DUMMY_SP };
916+
let pcx = &PatCtxt { cx, ty };
919917

920918
let column_ctors = column.iter().map(|p| p.ctor());
921919
let set = ConstructorSet::for_ty(pcx.cx, pcx.ty).split(pcx, column_ctors, false);
@@ -948,7 +946,7 @@ fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
948946
// columns may have different lengths in the presence of or-patterns (this is why we can't
949947
// reuse `Matrix`).
950948
let mut specialized_columns: Vec<Vec<_>> = (0..arity).map(|_| Vec::new()).collect();
951-
let relevant_patterns = column.iter().filter(|pat| ctor.is_covered_by(pcx, pat.ctor()));
949+
let relevant_patterns = column.iter().filter(|pat| ctor.is_covered_by(pat.ctor()));
952950
for pat in relevant_patterns {
953951
let specialized = pat.specialize(pcx, &ctor);
954952
for (subpat, sub_column) in specialized.iter().zip(&mut specialized_columns) {

0 commit comments

Comments
 (0)