Skip to content

Commit 7203e4e

Browse files
committed
---
yaml --- r: 273266 b: refs/heads/beta c: 9cc5ee3 h: refs/heads/master
1 parent 5d1b5c2 commit 7203e4e

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: ccc5e0732a95861de755cf14bec05d873bfa7481
26+
refs/heads/beta: 9cc5ee359a27b096d4945c672eb1383f4490fbf1
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc/middle/ty/sty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ impl<'tcx> TyS<'tcx> {
948948
}
949949
}
950950

951-
fn is_slice(&self) -> bool {
951+
pub fn is_slice(&self) -> bool {
952952
match self.sty {
953953
TyRawPtr(mt) | TyRef(_, mt) => match mt.ty.sty {
954954
TySlice(_) | TyStr => true,

branches/beta/src/librustc_mir/build/matches/test.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,28 @@ impl<'a,'tcx> Builder<'a,'tcx> {
175175
}
176176

177177
TestKind::Eq { ref value, ty } => {
178-
let expect = self.literal_operand(test.span, ty.clone(), Literal::Value {
179-
value: value.clone()
180-
});
178+
// If we're matching against &[u8] with b"...", we need to insert
179+
// an unsizing coercion, as the byte string has type &[u8; N].
180+
let expect = match *value {
181+
ConstVal::ByteStr(ref bytes) if ty.is_slice() => {
182+
let tcx = self.hir.tcx();
183+
let array_ty = tcx.mk_array(tcx.types.u8, bytes.len());
184+
let ref_ty = tcx.mk_imm_ref(tcx.mk_region(ty::ReStatic), array_ty);
185+
let array = self.literal_operand(test.span, ref_ty, Literal::Value {
186+
value: value.clone()
187+
});
188+
189+
let sliced = self.temp(ty);
190+
self.cfg.push_assign(block, test.span, &sliced,
191+
Rvalue::Cast(CastKind::Unsize, array, ty));
192+
Operand::Consume(sliced)
193+
}
194+
_ => {
195+
self.literal_operand(test.span, ty, Literal::Value {
196+
value: value.clone()
197+
})
198+
}
199+
};
181200
let val = Operand::Consume(lvalue.clone());
182201
let fail = self.cfg.start_new_block();
183202
let block = self.compare(block, fail, test.span, BinOp::Eq, expect, val.clone());

0 commit comments

Comments
 (0)