rust-lang / rust-lang/rust

`rustdoc` rejects (instead of ignoring) some unneeded `rustc` command-line flags like `-l...`

Open
#153,318 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-CLI C-bug needs-triage T-rustdoc
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Context

IIUC rustdoc needs to be invoked with the same command-like flags as rustc (similarly to clippy-driver) - this ensures that rustdoc sees the code in the same way as rustc does. For example:

  • the same --cfg flags should be used to include the same conditional code,
  • the same -L flags should be used so rustdoc can discover other crates that the current crate depends on

And it seems that rustdoc happily accepts most of the same flags as rustc, even ones that are not really needed for generating documentation - for example:

  • -Clink-arg=..., -Clto=no, -Copt-level=3 and other codegen flags
  • -Zdep-info-omit-d-target and other unstable flags
  • --cfg and -L flags mentioned above

Accepting the same flags as rustc is very desirable, because this helps build systems (e.g. gn used by Chromium, but probably also Bazel, Buck, etc.) to pass more-or-less the same command-line flags to rustdoc as the ones that are passed to rustc.

Problem

Repro steps:

$ which rustdoc
/usr/local/google/home/lukasza/.cargo/bin/rustdoc

$ rustdoc --version
rustdoc 1.96.0-nightly (80381278a 2026-03-01)

$ cat repro.rs
/// Documentation of `foo`.
pub fn foo() {
    todo!()
}

$ rustdoc repro.rs  # Works fine

$ rustdoc repro.rs -lglib-2.0  # PROBLEM: errors out
error: Unrecognized option: 'l'

Expected behavior: rustdoc accepts and ignores linking flags like -lglib-2.0

Actual behavior: rustdoc rejects -lglib-2.0 command-line flag

Contributor guide

Open the contributing guide

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 by reproducing the rustdoc repro.rs command with -lglib-2.0 and compare rustdoc's argument handling with rustc and clippy-driver. Trace the rustdoc command-line entry point to determine how linking flags are classified; done means rustdoc accepts and ignores -l flags while preserving existing behavior, with a regression test for the reported command.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.