Skip to content

Recommend -Zshare-generics=false with opt-level=z #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -438,4 +454,4 @@ use std::alloc::System;

#[global_allocator]
static A: System = System;
```
```
Copy link
Author

@Noratrieb Noratrieb Jun 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there was no trailing newline and my editor added it automatically, which seems fine to me