Skip to content

Commit 548cc4d

Browse files
committed
projection and coercion improvements
1 parent e58eeb8 commit 548cc4d

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
6363
let project = PlaceElem::Subslice {
6464
from: 0 as u64,
6565
to: prefix.len() as u64,
66-
from_end: false,
67-
}; // or use a projection??
66+
from_end: !exact_size,
67+
};
6868

6969
let match_pair = self.valtree_to_match_pair(
7070
src_path.ty,
@@ -81,7 +81,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
8181
let elem = ProjectionElem::ConstantIndex {
8282
offset: idx as u64,
8383
min_length,
84-
from_end: false,
84+
from_end: !exact_size,
8585
};
8686
MatchPairTree::for_pattern(place.clone_project(elem), subpattern, self)
8787
}));
@@ -157,7 +157,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
157157
elem_ty: Ty<'tcx>,
158158
) -> MatchPairTree<'pat, 'tcx> {
159159
let tcx = self.tcx;
160-
161160
tracing::warn!("source pattern type: {:?}", src_pat_ty);
162161
let (const_ty, pat_ty) = match src_pat_ty.kind() { // wait is source path the wrong thing to care about?
163162
ty::Slice(_) => (

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -442,14 +442,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
442442
(ty, place)
443443
};
444444

445-
match (ty.peel_refs().kind(), expect_ty.peel_refs().kind()) {
446-
(ty::Slice(_), ty::Array(elem_ty, _)) => {
447-
(_, expect) = coerce(expect_ty, expect, *elem_ty);
448-
}
449-
(ty::Array(elem_ty, _), ty::Slice(_)) => {
450-
(ty, val) = coerce(ty, val, *elem_ty);
451-
}
452-
_ => (),
445+
if let ty::Array(elem_ty, _) = ty.peel_refs().kind() {
446+
(ty, val) = coerce(ty, val, *elem_ty);
447+
}
448+
449+
if let ty::Array(elem_ty, _) = expect_ty.peel_refs().kind() {
450+
(_, expect) = coerce(expect_ty, expect, *elem_ty);
453451
}
454452

455453
// Figure out the type on which we are calling `PartialEq`. This involves an extra wrapping
@@ -468,8 +466,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
468466
_ => span_bug!(source_info.span, "invalid type for non-scalar compare: {}", ty),
469467
};
470468

471-
tracing::warn!("compare_ty: {:?}", compare_ty);
472-
473469
let eq_def_id =
474470
self.tcx.require_lang_item(LangItem::MatchLoweredCmp, Some(source_info.span));
475471
let method = trait_method(self.tcx, eq_def_id, sym::do_match, [compare_ty, compare_ty]);

library/core/src/cmp/pattern.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ where
88
fn do_match(&self, other: &Rhs) -> bool;
99
}
1010

11+
// other types?
12+
1113
impl const MatchLoweredCmp for u8 {
1214
fn do_match(&self, other: &Self) -> bool {
1315
*self == *other
1416
}
1517
}
1618

19+
// shouldn't be const
1720
impl const MatchLoweredCmp for str {
1821
#[rustc_allow_const_fn_unstable(const_trait_impl)]
1922
fn do_match(&self, other: &Self) -> bool {

0 commit comments

Comments
 (0)