rust-lang / rust-lang/rfcs

Allow opting out of specific parts of core crate (e.g. core::fmt)

Open
#3,665 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

In embedded systems development, there's usually a small maximum binary size. (e.g. 8KiB).
The size of core::fmt when compiled into the executable is too big for this.

Take a freestanding, x86_64-unknown-none, panic="abort" executable with 3 functions: A panic handler, a function named panik, and the _start function. In both the panic and panik functions, the only expression is loop {unsafe {asm!("hlt");}}. In the _start function, the only expression is either panic!(); or panik();

If you run cargo bloat --release --target=x86_64-unknown-none on the program's source when the only expression in _start is panic!();, the resulting executable size is 665.4KiB, which is 83 times the hypothetical size limit of our executable.

However, if you run the same command when the function in _start used is panik();, the executable size is now only 1.8KiB, which is only 25% of the limit: 332 times smaller.

It would be very nice if we could opt out of using parts of core like core::fmt instead of struggling to avoid compiling it. When opted out of part of core, the compiler will output an error (E0412) upon compiling something that is in or depends on the opted out portion, instead of silently compiling it in. My suggestion for the syntax is unuse core::foo::bar;, though other syntax is fine.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue's freestanding x86_64-unknown-none example and its cargo bloat comparison between panic!() and panik(); no source files or tests are named. Review the proposed opt-out behavior, including the suggested unuse syntax and E0412 errors, and determine the design scope and acceptance criteria before implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.