rc_buffer lint is dangerous as it changes runtime behaviour #6170
Labels
C-bug
Category: Clippy is not doing the correct thing
good-first-issue
These issues are a good way to get started with Clippy
L-suggestion
Lint: Improving, adding or fixing lint suggestions
clippy warns if one tries to use a type like
Rc<Vec<T>>
, e.g.This is dangerous as creating a
Rc<[T]>
causes amemcpy
of the whole memory area with all the elements, while creating anRc<Vec<T>>
simply copies over the 3 pointers inside theVec
without copying all the elements.A better suggestion would probably be
Rc<Box<[T]>>
as that has the same runtime behaviour, but even independent of that it can be useful to have aVec
inside anRc
/Arc
in combination with themake_mut()
/get_mut()
API.The lint should probably be at least disabled by default.
The same also applies to
Rc<String>
vsRc<str>
.The text was updated successfully, but these errors were encountered: