`rustdoc` rejects (instead of ignoring) some unneeded `rustc` command-line flags like `-l...`
Nobody has claimed this yet.
- 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
--cfgflags should be used to include the same conditional code, - the same
-Lflags should be used sorustdoccan 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=3and other codegen flags-Zdep-info-omit-d-targetand other unstable flags--cfgand-Lflags 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
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 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