diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-10-19 05:40:54 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-19 05:40:54 +0200 |
| commit | c3cfa581571a688ec2747e9b22e4013f4d23d729 (patch) | |
| tree | 591f4718791555b2b7dc57d8fb352f83c3111446 /src/test | |
| parent | a0724d72b0419a4e458c0174af27c85817b1f7ba (diff) | |
| parent | f8b2f91c4879bbb37ed64623373a1b95b658bc20 (diff) | |
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
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/consts/const-eval/issue-84957-const-str-as-bytes.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/ui/consts/const-eval/issue-84957-const-str-as-bytes.rs b/src/test/ui/consts/const-eval/issue-84957-const-str-as-bytes.rs new file mode 100644 index 00000000000..7e235c4911c --- /dev/null +++ b/src/test/ui/consts/const-eval/issue-84957-const-str-as-bytes.rs @@ -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); + } +} |
