Closed
Description
Defining a function that has a &mut Box<[T]>
parameter triggers the borrowed_box
lint, recommending it be replaced with a &mut [T]
. It's possible to have a function that replaces the boxed slice with a different allocation (e.g. a slice with a different size), which cannot be done if the parameter is just a slice reference.
Example:
pub fn maybe_sets_box(boxed_slice: &mut Box<[i32]>) {
if boxed_slice.is_empty() {
let mut data = Vec::with_capacity(1);
data.push(12);
*boxed_slice = data.into_boxed_slice();
}
}