`write_to_prefix` generates panic path
Open
- Dominant language
- Rust
- Stars
- 2.6k
- Forks
- 179
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 29
Description
The `write_to_prefix` function is generating a panic path in our code, and I am pretty sure it is the `bytes[..size].copy_from_slice(self.as_bytes());` line. The compiler doesn't have enough information to elide the slice comparison check.
If the code was written like the following, the compiler should not generate a panic path
```rust
fn write_to_prefix(&self, mut bytes: B) -> Option<()> {
let source = self.as_bytes();
if bytes.len() < source.len() {
return None;
}
bytes[..size].copy_from_slice(source);
Some(())
}
```
Contributor guide
Assessment
This issue has not been assessed yet.