This lint is meant to fire only in simple cases because analyzing the problem in general looks difficult to me. But as usual with Clippy even catching the basic situations is able to find tons of cases. This lint is meant to suggest the programmer to replace some useless vec![] allocations with regular slice literals that are short enough to avoid stack problems.
Advantage
We avoid heap allocations, LLVM generates less code, the compilation time probably decreases as well, perhaps the executable binary decreases in size a bit.
Drawbacks
We could change the meaning of the program. A Vec is a more flexible data structure compared to a slice. This lint could confuse Rust novices a bit.
What it does
This lint is meant to fire only in simple cases because analyzing the problem in general looks difficult to me. But as usual with Clippy even catching the basic situations is able to find tons of cases. This lint is meant to suggest the programmer to replace some useless vec![] allocations with regular slice literals that are short enough to avoid stack problems.
Advantage
We avoid heap allocations, LLVM generates less code, the compilation time probably decreases as well, perhaps the executable binary decreases in size a bit.
Drawbacks
We could change the meaning of the program. A Vec is a more flexible data structure compared to a slice. This lint could confuse Rust novices a bit.
Example
This code derives from the code of issue #13268.
Could be written as: