-Zno-link is broken (take 2)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
echo "pub fn hello() {}" > dep.rs
echo "extern crate dep; fn main() { dep::hello() }" > main.rs
rustc +nightly --crate-name dep dep.rs --crate-type lib --emit=metadata,link
rustc +nightly --crate-name foo main.rs --crate-type bin --extern dep=libdep.rmeta -Zno-link
I expected to see this happen: It compiles, but doesn't link anything.
Instead, this happened:
error: crate `dep` required to be available in rlib format, but was not found in this form
error: aborting due to 1 previous error
Meta
Reported by @weihanglo at https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/How.20to.20use.20.60-Zno-link.60.2F.60-Zlink-only.60.20correctly/with/520969639
Previous breakage: https://github.com/rust-lang/rust/issues/77857
rustc --version --verbose:
rustc 1.89.0-nightly (45f256d9d 2025-05-27)
binary: rustc
commit-hash: 45f256d9d7cffb66185c0bf1b8a864cba79db90c
commit-date: 2025-05-27
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the shell reproduction with rustc +nightly and trace how -Zno-link handles the --extern dep=libdep.rmeta input. Investigate the compiler's crate-format and linking checks around this path. Done means the command compiles without requiring dep in rlib format and does not link anything.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100