Skip to content

-Zno-link is broken (take 2) #141706

Open
Open
@bjorn3

Description

@bjorn3

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: #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

Metadata

Metadata

Assignees

No one assigned

    Labels

    -Zno-linkUnstable option: -Zno-linkA-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions