Skip to content
This repository was archived by the owner on May 23, 2024. It is now read-only.

Commit da245df

Browse files
committed
Add 82034
Issue: rust-lang/rust#82034
1 parent 983f014 commit da245df

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

ices/82034.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
rustc --test -C incremental=foo - <<'EOF'
4+
#![feature(const_generics)]
5+
#![feature(const_evaluatable_checked)]
6+
#![allow(incomplete_features)]
7+
pub trait IsTrue {}
8+
pub trait IsFalse {}
9+
10+
pub struct Assert<const CHECK: bool> {}
11+
12+
impl IsTrue for Assert<true> {}
13+
impl IsFalse for Assert<false> {}
14+
15+
pub struct SliceConstWriter<'a, const N: usize> {
16+
ptr: &'a mut [u8]
17+
}
18+
impl<'a, const N: usize> SliceConstWriter<'a, {N}> {
19+
pub fn from_slice(vec: &'a mut [u8]) -> Self {
20+
Self {
21+
ptr: vec
22+
}
23+
}
24+
25+
pub fn convert<const NN: usize>(mut self) -> SliceConstWriter<'a, {NN}> {
26+
SliceConstWriter {
27+
ptr: self.ptr
28+
}
29+
}
30+
}
31+
32+
impl<'a, const N: usize> SliceConstWriter<'a, {N}> where Assert::<{N >= 2}>: IsTrue {
33+
// broken
34+
pub fn write_u8(mut self) -> SliceConstWriter<'a, {N-2}> {
35+
self.convert()
36+
}
37+
38+
//working
39+
// pub fn write_u8(mut self) -> SliceConstWriter<'a, {N-2}> {
40+
// SliceConstWriter {
41+
// ptr: self.ptr
42+
// }
43+
// }
44+
}
45+
46+
47+
#[cfg(test)]
48+
mod tests {
49+
use crate::SliceConstWriter;
50+
51+
#[test]
52+
fn it_works() {
53+
let mut buff = [0u8; 128];
54+
let mut a = SliceConstWriter::<10>::from_slice(&mut buff);
55+
56+
let mut a = a.write_u8().write_u8().write_u8().write_u8().write_u8();
57+
}
58+
}
59+
EOF

0 commit comments

Comments
 (0)