Skip to content

Commit

Permalink
Rollup merge of #89997 - cameron1024:const-str-as-bytes-ice, r=JohnTitor
Browse files Browse the repository at this point in the history
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
  • Loading branch information
matthiaskrgr authored Oct 19, 2021
2 parents a0724d7 + f8b2f91 commit c3cfa58
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/test/ui/consts/const-eval/issue-84957-const-str-as-bytes.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit c3cfa58

Please sign in to comment.