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
This commit is contained in:
Matthias Krüger 2021-10-19 05:40:54 +02:00 committed by GitHub
commit c3cfa58157
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,28 @@
// build-pass
trait Foo {}
struct Bar {
bytes: &'static [u8],
func: fn(&Box<dyn Foo>),
}
fn example(_: &Box<dyn Foo>) {}
const BARS: &[Bar] = &[
Bar {
bytes: "0".as_bytes(),
func: example,
},
Bar {
bytes: "0".as_bytes(),
func: example,
},
];
fn main() {
let x = todo!();
for bar in BARS {
(bar.func)(&x);
}
}