Skip to content

Commit a059b15

Browse files
committed
narrow the bug down to place locations
1 parent d224005 commit a059b15

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

compiler/rustc_mir_build/src/builder/matches/match_pair.rs

+24-12
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
3030

3131
// We don't consider an empty subslice as a constant pattern subslice.
3232
fn is_constant_pattern_subslice(&self, subslice: &[Box<Pat<'tcx>>]) -> bool {
33-
!subslice.is_empty() && subslice.iter().all(|p| self.is_constant_pattern(p))
33+
subslice.len() > 1 && subslice.iter().all(|p| self.is_constant_pattern(p))
3434
}
3535

3636
// TODO: expand beyond u8
3737
fn is_constant_pattern(&self, pat: &Pat<'tcx>) -> bool {
3838
if let PatKind::Constant { value } = pat.kind
3939
&& let Const::Ty(_, const_) = value
4040
&& let ty::ConstKind::Value(ty, valtree) = const_.kind()
41+
&& let ty::ValTree::Leaf(scalar) = valtree
4142
&& self.tcx.types.u8 == ty
42-
&& matches!(valtree, ty::ValTree::Leaf(_))
43+
&& scalar.to_u8() != b'_'
4344
{
4445
true
4546
} else {
@@ -78,7 +79,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7879
valtree: ty::ValTree<'tcx>,
7980
place: PlaceBuilder<'tcx>,
8081
elem_ty: Ty<'tcx>,
81-
) -> MatchPairTree<'pat, 'tcx> {
82+
) -> Option<MatchPairTree<'pat, 'tcx>> {
8283
let tcx = self.tcx;
8384
let (const_ty, pat_ty) = if base_pat_ty.is_slice() {
8485
(
@@ -91,9 +92,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
9192
)
9293
} else {
9394
//let arr_ty = Ty::new_array(tcx, elem_ty, subslice_len);
94-
let arr_ty = Ty::new_slice(tcx, elem_ty);
95-
let pat_ty = Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, arr_ty);
96-
(arr_ty, pat_ty)
95+
//let arr_ty = Ty::new_imm_ref(
96+
// tcx,
97+
// tcx.lifetimes.re_erased,
98+
// Ty::new_array(tcx, elem_ty, subslice_len),
99+
//);
100+
//let pat_ty = Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, Ty::new_slice(tcx, elem_ty));
101+
//(arr_ty, pat_ty)
102+
return None;
97103
};
98104

99105
let r#const = ty::Const::new(tcx, ty::ConstKind::Value(const_ty, valtree));
@@ -107,12 +113,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
107113

108114
let test_case = TestCase::Constant { value: r#const2 };
109115

110-
MatchPairTree {
116+
Some(MatchPairTree {
111117
place: Some(place.to_place(self)),
112118
test_case,
113119
subpairs: Vec::new(),
114120
pattern,
115-
}
121+
})
116122
}
117123

118124
/// Builds [`MatchPairTree`] subtrees for the prefix/middle/suffix parts of an
@@ -143,6 +149,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
143149
((prefix.len() + suffix.len()).try_into().unwrap(), false)
144150
};
145151

152+
let mut not = false;
153+
146154
// Here we try to special-case constant pattern subslices into valtrees to generate
147155
// nicer MIR.
148156
// Try to perform simplification of a constant pattern slice `prefix` sequence into
@@ -151,16 +159,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
151159
let elem_ty = prefix[0].ty;
152160
let prefix_valtree = self.simplify_const_pattern_slice_into_valtree(prefix);
153161
// FIXME(jieyouxu): triple check these place calculations!
154-
let match_pair = self.valtree_to_match_pair(
162+
if let Some(match_pair) = self.valtree_to_match_pair(
155163
base_pat.ty,
156164
base_pat.span,
157165
prefix.len() as u64,
158166
prefix_valtree,
159167
place.base().into(),
160168
elem_ty,
161-
);
162-
match_pairs.push(match_pair);
163-
} else {
169+
) {
170+
match_pairs.push(match_pair);
171+
not = true;
172+
}
173+
}
174+
175+
if !not {
164176
match_pairs.extend(prefix.iter().enumerate().map(|(idx, subpattern)| {
165177
let elem =
166178
ProjectionElem::ConstantIndex { offset: idx as u64, min_length, from_end: false };

0 commit comments

Comments
 (0)