mirror of
https://github.com/roc-lang/roc.git
synced 2024-08-17 06:41:22 +03:00
partial clippy fixes
This commit is contained in:
parent
26f0448a94
commit
2ac6243e72
@ -361,7 +361,7 @@ impl RocStr {
|
|||||||
let ptr = if len < big_string.capacity() {
|
let ptr = if len < big_string.capacity() {
|
||||||
// We happen to have excess capacity already, so we will be able
|
// We happen to have excess capacity already, so we will be able
|
||||||
// to write the terminator into the first byte of excess capacity.
|
// to write the terminator into the first byte of excess capacity.
|
||||||
big_string.ptr_to_first_elem() as *mut u8
|
big_string.ptr_to_first_elem()
|
||||||
} else {
|
} else {
|
||||||
// We always have an allocation that's even bigger than necessary,
|
// We always have an allocation that's even bigger than necessary,
|
||||||
// because the refcount bytes take up more than the 1B needed for
|
// because the refcount bytes take up more than the 1B needed for
|
||||||
@ -376,7 +376,7 @@ impl RocStr {
|
|||||||
//
|
//
|
||||||
// IMPORTANT: Must use ptr::copy instead of ptr::copy_nonoverlapping
|
// IMPORTANT: Must use ptr::copy instead of ptr::copy_nonoverlapping
|
||||||
// because the regions definitely overlap!
|
// because the regions definitely overlap!
|
||||||
ptr::copy(big_string.ptr_to_first_elem() as *mut u8, alloc_ptr, len);
|
ptr::copy(big_string.ptr_to_first_elem(), alloc_ptr, len);
|
||||||
|
|
||||||
alloc_ptr
|
alloc_ptr
|
||||||
};
|
};
|
||||||
@ -388,7 +388,7 @@ impl RocStr {
|
|||||||
// The backing list was not unique, so we can't mutate it in-place.
|
// The backing list was not unique, so we can't mutate it in-place.
|
||||||
// ask for `len + 1` to store the original string and the terminator
|
// ask for `len + 1` to store the original string and the terminator
|
||||||
with_stack_bytes(len + 1, |alloc_ptr: *mut u8| {
|
with_stack_bytes(len + 1, |alloc_ptr: *mut u8| {
|
||||||
let elem_ptr = big_string.ptr_to_first_elem() as *mut u8;
|
let elem_ptr = big_string.ptr_to_first_elem();
|
||||||
|
|
||||||
// memcpy the bytes into the stack allocation
|
// memcpy the bytes into the stack allocation
|
||||||
std::ptr::copy_nonoverlapping(elem_ptr, alloc_ptr, len);
|
std::ptr::copy_nonoverlapping(elem_ptr, alloc_ptr, len);
|
||||||
|
@ -255,9 +255,9 @@ mod tests {
|
|||||||
decode_u32(&[0xff, 0xff, 0xff, 0xff, 0x0f]),
|
decode_u32(&[0xff, 0xff, 0xff, 0xff, 0x0f]),
|
||||||
Ok((u32::MAX, MAX_SIZE_ENCODED_U32))
|
Ok((u32::MAX, MAX_SIZE_ENCODED_U32))
|
||||||
);
|
);
|
||||||
assert!(matches!(decode_u32(&[0x80; 6]), Err(_)));
|
assert!(decode_u32(&[0x80; 6]).is_err());
|
||||||
assert!(matches!(decode_u32(&[0x80; 2]), Err(_)));
|
assert!(decode_u32(&[0x80; 2]).is_err());
|
||||||
assert!(matches!(decode_u32(&[]), Err(_)));
|
assert!(decode_u32(&[]).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user