Skip to content

Commit

Permalink
Merge pull request #18 from dtolnay/cfgdoc
Browse files Browse the repository at this point in the history
Update for stable cfg(doc)
  • Loading branch information
dtolnay authored Mar 5, 2023
2 parents 305c9b4 + cebfe81 commit 763611b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
20 changes: 6 additions & 14 deletions readonly-fields/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,26 +207,18 @@ field were declared `pub`.

### Third attempt

We can use `#[cfg(rustdoc)]` to distinguish when documentation is being
rendered, though this cfg is currently available on nightly only. The tracking
issue is [rust-lang/rust#43781].
We can use [`#[cfg(doc)]`][cfgdoc] to distinguish when documentation is being
rendered, which is available since Rust 1.41.

[rust-lang/rust#43781]: https://github.com/rust-lang/rust/issues/43781

I ended up using a Cargo config to have rustdoc pass some different cfg.

```toml
[build]
rustdocflags = ["--cfg", "oqueue_docs"]
```
[cfgdoc]: https://doc.rust-lang.org/1.67.0/rustdoc/advanced-features.html#cfgdoc-documenting-platform-specific-or-feature-specific-information

```rust
#[repr(C)]
pub struct Task {
#[cfg(oqueue_docs)]
#[cfg(doc)]
pub index: usize,

#[cfg(not(oqueue_docs))]
#[cfg(not(doc))]
index: usize,

// other private fields
Expand Down Expand Up @@ -273,7 +265,7 @@ the behavior as an attribute macro][readonly] is the easy part:

```rust
/// ...
#[readonly::make(doc = oqueue_docs)]
#[readonly::make]
pub struct Task {
/// ...
///
Expand Down
2 changes: 0 additions & 2 deletions readonly-fields/demo/.cargo/config.toml

This file was deleted.

4 changes: 2 additions & 2 deletions readonly-fields/demo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ mod oqueue {
#[derive(Default)]
#[repr(C)]
pub struct Task {
#[cfg(oqueue_docs)]
#[cfg(doc)]
pub index: usize,

#[cfg(not(oqueue_docs))]
#[cfg(not(doc))]
index: usize,

// Other private fields:
Expand Down

0 comments on commit 763611b

Please sign in to comment.