Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b061ec2

Browse files
committedMar 17, 2016
---
yaml --- r: 282026 b: refs/heads/stable c: 9cc5ee3 h: refs/heads/master
1 parent adafc2f commit b061ec2

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
@@ -29,7 +29,7 @@ refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: 3c795e08d6f4a532f12f3f8e1837db5e0647f8b0
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: ccc5e0732a95861de755cf14bec05d873bfa7481
32+
refs/heads/stable: 9cc5ee359a27b096d4945c672eb1383f4490fbf1
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

‎branches/stable/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/stable/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)
Please sign in to comment.