@@ -175,9 +175,28 @@ impl<'a,'tcx> Builder<'a,'tcx> {
175
175
}
176
176
177
177
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
+ } ;
181
200
let val = Operand :: Consume ( lvalue. clone ( ) ) ;
182
201
let fail = self . cfg . start_new_block ( ) ;
183
202
let block = self . compare ( block, fail, test. span , BinOp :: Eq , expect, val. clone ( ) ) ;
0 commit comments