Skip to content

Commit c3cfa58

Browse files
authored
Rollup merge of #89997 - cameron1024:const-str-as-bytes-ice, r=JohnTitor
Add test for issue #84957 - `str.as_bytes()` in a `const` expression Hi, this PR adds a test for issue #84957 . I'm quite new to rustc so let me know if there's anything else that needs doing 😄 Closes #84957
2 parents a0724d7 + f8b2f91 commit c3cfa58

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// build-pass
2+
3+
trait Foo {}
4+
5+
struct Bar {
6+
bytes: &'static [u8],
7+
func: fn(&Box<dyn Foo>),
8+
}
9+
fn example(_: &Box<dyn Foo>) {}
10+
11+
const BARS: &[Bar] = &[
12+
Bar {
13+
bytes: "0".as_bytes(),
14+
func: example,
15+
},
16+
Bar {
17+
bytes: "0".as_bytes(),
18+
func: example,
19+
},
20+
];
21+
22+
fn main() {
23+
let x = todo!();
24+
25+
for bar in BARS {
26+
(bar.func)(&x);
27+
}
28+
}

0 commit comments

Comments
 (0)