# Docs.rs - build on multiple toolchains

**URL:** <https://users.rust-lang.org/t/docs-rs-build-on-multiple-toolchains/140639>\
**Category:** help\
**Created:** [June 11, 2026, 1:18pm UTC](https://users.rust-lang.org/t/docs-rs-build-on-multiple-toolchains/140639 "2026-06-11T13:18:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MusicalNinjaDad](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/musicalninjadad/32/41229_2.png) [@MusicalNinjaDad](https://users.rust-lang.org/u/MusicalNinjaDad)\
**Post date:** [June 11, 2026, 1:18pm UTC](https://users.rust-lang.org/t/docs-rs-build-on-multiple-toolchains/140639/1 "2026-06-11T13:18:28Z")

</div>

I know there are options to define which targets are built for docs.rs and for multiple targets to be combined into a single documentation.

Is it also possible to have docs.rs build stable & nightly then combine the documentation?

Background: I have a crate which provides a consistent stable interface and leverages experimental features where available. Currently the docs only show the implementation details for the toolchain defined in rust-toolchain.toml (nightly) and are therefore missing the stable alternatives. This makes it look like a chunk of the API surface is nightly-only.

---

<div class="post-metadata">

**Author:** ![kpreid](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/kpreid/32/22420_2.png) [@kpreid](https://users.rust-lang.org/u/kpreid)\
**Post date:** [June 11, 2026, 1:39pm UTC](https://users.rust-lang.org/t/docs-rs-build-on-multiple-toolchains/140639/2 "2026-06-11T13:39:22Z")

</div>

docs.rs uses nightly features of `rustdoc`, so it always uses the nightly toolchain and can't be configured otherwise.

That said, if your automatic use of nightly features is _visible in the documentation_, that seems likely to be something that will cause trouble by itself, and you should likely reconsider it (but I don't have the details).

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/bjorn3/32/5255_2.png) [@bjorn3](https://users.rust-lang.org/u/bjorn3)\
**Post date:** [June 11, 2026, 1:39pm UTC](https://users.rust-lang.org/t/docs-rs-build-on-multiple-toolchains/140639/3 "2026-06-11T13:39:33Z")

</div>

docs.rs only supports building using the latest nightly. Would it be possible to instead of detect if you are running on stable or nightly rather add a nightly cargo feature to allow the user to opt-in to unstable features? This avoids breakage when unstable features in rustc change when the user didn't need them but is using nightly for unrelated reasons. And rustdoc would show a badge for every item that is only usable when the nightly feature is enabled.

---

<div class="post-metadata">

**Author:** ![MusicalNinjaDad](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/musicalninjadad/32/41229_2.png) [@MusicalNinjaDad](https://users.rust-lang.org/u/MusicalNinjaDad)\
**Post date:** [June 11, 2026, 2:15pm UTC](https://users.rust-lang.org/t/docs-rs-build-on-multiple-toolchains/140639/4 "2026-06-11T14:15:53Z")

</div>

It's a bit of an edge case: the crate provides an ergonomic wrapper around the nightly feature `proc_macro_diagnostic` in a way which works (definition below) today on both nightly and stable. It also leverages additional nightly features (related to `trait Try`) where available and will continue to work as features are stabilised (in any order - testing this was a nice challenge).

"Crate goal: it just works":

- same code compiles on nightly & stable
- all key functionality is available on nightly & stable
- where (nice-to-have) functionality cannot be provided on stable, the API is designed in a way that this will not affect the overall result
- some ergonomic benefits are missing on stable
- code continues to compile as features are stabilised (in any order) & takes advantage of stable features without downstream crates needing to change anything
- it is not possible to write code on nightly which will fail on stable (reciprocal goal missed in one specific, documented & hopefully unlikely case)

The above precludes using opt-in features in a meaningful way for the next-downstream to decide what to support.

To achieve this:

1. I am automatically generating cfg flag pairs for each feature:
  - `unstable_proc_macro_diagnostic`
  - `has_proc_macro_diagnostic`

2. I prefix `lib.rs` with `!#[cfg_attr(unstable_proc_macro_diagnostic, feature(proc_macro_diagnostic))]`
3. I have paired code segments gated `#[cfg(has_proc_macro_diagnostic)]` / `#[cfg(not(has_proc_macro_diagnostic))]`

Where a public function or type is gated, the nightly version shows on docs.rs, with a note "_Available on `has_proc_macro_diagnostic` only_" and the stable version is not shown.

For those interested in helping spot what I did wrong:

- Crate is here: [MusicalNinjaDad/proc\_macro2\_diagnostic: Use `Diagnostic` compiler messages from proc\_macro2 code with `Result`-like syntax](https://github.com/MusicalNinjaDad/proc_macro2_diagnostic)
- The build script leverages [ninja-build\_rs](https://github.com/MusicalNinjaDad/rust/tree/main/ninja-build_rs) which builds on `autocfg`

---

<div class="post-metadata">

**Author:** ![kpreid](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/kpreid/32/22420_2.png) [@kpreid](https://users.rust-lang.org/u/kpreid)\
**Post date:** [June 11, 2026, 2:22pm UTC](https://users.rust-lang.org/t/docs-rs-build-on-multiple-toolchains/140639/5 "2026-06-11T14:22:49Z")

</div>

> [@MusicalNinjaDad](#):
>
> Where a public function or type is gated, the nightly version shows on docs.rs, with a note "_Available on `has_proc_macro_diagnostic` only_" and the stable version is not shown.

You can override the displayed badges with `#[doc(cfg(...))]`.

```rust
#![cfg_attr(docsrs, feature(doc_cfg))]

#[cfg(has_proc_macro_diagnostic)]
#[cfg_attr(docsrs, doc(cfg(true)))]
pub fn example() {}

```

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [September 9, 2026, 2:23pm UTC](https://users.rust-lang.org/t/docs-rs-build-on-multiple-toolchains/140639/6 "2026-09-09T14:23:05Z")

</div>

Closed on September 9, 2026, 2:23pm UTC

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.
