Skip to content

Commit a1b74bb

Browse files
committed
Add test for matching on constants with reference type
1 parent e66f5a3 commit a1b74bb

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/librustc_mir/build/matches/test.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
288288
Rvalue::Cast(CastKind::Unsize, val, ty));
289289
}
290290
if opt_ref_test_ty.is_some() {
291-
let array = self.literal_operand(test.span, value.ty, Literal::Value {
292-
value
293-
});
291+
let array = self.literal_operand(
292+
test.span,
293+
value.ty,
294+
Literal::Value {
295+
value
296+
},
297+
);
294298

295299
let slice = self.temp(ty, test.span);
296300
self.cfg.push_assign(block, source_info, &slice,

src/test/run-pass/ctfe/references.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
const FOO: &[u8] = b"foo";
12+
const BAR: &[u8] = &[1, 2, 3];
13+
14+
const BOO: &i32 = &42;
15+
16+
fn main() {
17+
match &[1u8, 2, 3] as &[u8] {
18+
FOO => panic!("a"),
19+
BAR => println!("b"),
20+
_ => panic!("c"),
21+
}
22+
23+
match b"foo" as &[u8] {
24+
FOO => println!("a"),
25+
BAR => panic!("b"),
26+
_ => panic!("c"),
27+
}
28+
29+
match &43 {
30+
&42 => panic!(),
31+
BOO => panic!(),
32+
_ => println!("d"),
33+
}
34+
}

0 commit comments

Comments
 (0)