From 5b268e971c07552fc3791e8681ac2f7f1981b3e4 Mon Sep 17 00:00:00 2001 From: nora <48135649+Noratrieb@users.noreply.github.com> Date: Sat, 7 Jun 2025 16:10:07 +0200 Subject: [PATCH] Recommend -Zshare-generics=false opt-level=z|s implicitly enables -Zshare-generics=true, which sometimes has a positive and sometimes has a negative impact. Update README.md --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0995488..9bdf497 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,22 @@ Enable this in `Cargo.toml`: panic = "abort" ``` +# (Un)Share Generics + +![Minimum Rust: Nightly](https://img.shields.io/badge/Minimum%20Rust%20Version-nightly-orange.svg) + +Currently Rust enables `-Zshare-generics` implicitly for opt-level `"s"` and `"z"`. +Just like `"s"` vs `"z"`, this can sometimes be helpful and sometimes cause larger binaries. + +To avoid sharing generics, use the unstable +`rustc` `-Zshare-generics` flag: +flag: + +```bash +$ RUSTFLAGS="-Zshare-generics=false" cargo +nightly build --release +``` + + # Remove Location Details ![Minimum Rust: Nightly](https://img.shields.io/badge/Minimum%20Rust%20Version-nightly-orange.svg) @@ -438,4 +454,4 @@ use std::alloc::System; #[global_allocator] static A: System = System; -``` \ No newline at end of file +```