summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/computer/programming/programming_languages/rust.md19
1 files changed, 19 insertions, 0 deletions
diff --git a/content/computer/programming/programming_languages/rust.md b/content/computer/programming/programming_languages/rust.md
index d7d5c01..b0032bc 100644
--- a/content/computer/programming/programming_languages/rust.md
+++ b/content/computer/programming/programming_languages/rust.md
@@ -37,3 +37,22 @@ weight = 1
* [clap](https://clap.rs) - State of the art commandline interface building and parsing
+
+# Notes
+
+---
+
+The Rust standard library actually optimizes zero-size-type allocations away,
+for example
+[here](https://github.com/rust-lang/rust/blob/866335b337964c79372cd6b1b1213f168efd311f/library/alloc/src/raw_vec.rs#L188),
+allocations are prevented if the generic type `T` is zero sized.
+
+Thus, the following code will never allocate after the first allocation:
+
+```rust
+let _ = std::iter::repeat(()).collect::<Vec<()>>();
+```
+
+It does still panic, though, because the element counter overflows.
+
+---