Skip to content

Commit

Permalink
Rollup merge of rust-lang#89997 - cameron1024:const-str-as-bytes-ice,…
Browse files Browse the repository at this point in the history
… r=JohnTitor

Add test for issue rust-lang#84957 - `str.as_bytes()` in a `const` expression

Hi, this PR adds a test for issue rust-lang#84957 . I'm quite new to rustc so let me know if there's anything else that needs doing 😄

Closes rust-lang#84957
  • Loading branch information
matthiaskrgr committed Oct 18, 2021
2 parents a284d74 + f8b2f91 commit b434eb6
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 b434eb6

Please sign in to comment.