]> git.lizzy.rs Git - rust.git/commitdiff
Stabilize cfg rustdoc
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Fri, 6 Sep 2019 08:51:52 +0000 (10:51 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Thu, 21 Nov 2019 14:37:36 +0000 (15:37 +0100)
src/doc/rustdoc/src/the-doc-attribute.md
src/libsyntax/feature_gate/builtin_attrs.rs
src/test/ui/cfg-rustdoc.rs [new file with mode: 0644]
src/test/ui/cfg-rustdoc.stderr [new file with mode: 0644]
src/test/ui/feature-gates/feature-gate-doc_cfg-cfg-rustdoc.rs [deleted file]
src/test/ui/feature-gates/feature-gate-doc_cfg-cfg-rustdoc.stderr [deleted file]

index 80ac405eb2f2a72d9d6bbcac0e1b15ce35e027c7..3aaac9268ffcf38cc76fcb0fcf73c8726bd0350d 100644 (file)
@@ -214,3 +214,34 @@ the `strip-hidden` pass is removed.
 Since primitive types are defined in the compiler, there's no place to attach documentation
 attributes. This attribute is used by the standard library to provide a way to generate
 documentation for primitive types.
 Since primitive types are defined in the compiler, there's no place to attach documentation
 attributes. This attribute is used by the standard library to provide a way to generate
 documentation for primitive types.
+
+## `#[cfg(rustdoc)]`: Documenting platform-/feature-specific information
+
+For conditional compilation, Rustdoc treats your crate the same way the compiler does: Only things
+from the host target are available (or from the given `--target` if present), and everything else is
+"filtered out" from the crate. This can cause problems if your crate is providing different things
+on different targets and you want your documentation to reflect all the available items you
+provide.
+
+If you want to make sure an item is seen by Rustdoc regardless of what platform it's targeting,
+you can apply `#[cfg(rustdoc)]` to it. Rustdoc sets this whenever it's building documentation, so
+anything that uses that flag will make it into documentation it generates. To apply this to an item
+with other `#[cfg]` filters on it, you can write something like `#[cfg(any(windows, rustdoc))]`.
+This will preserve the item either when built normally on Windows, or when being documented
+anywhere.
+
+Please note that this feature won't be passed when building doctests.
+
+Example:
+
+```rust
+/// Token struct that can only be used on Windows.
+#[cfg(any(windows, rustdoc))]
+pub struct WindowsToken;
+/// Token struct that can only be used on Unix.
+#[cfg(any(unix, rustdoc))]
+pub struct UnixToken;
+```
+
+Here, the respective tokens can only be used by dependent crates on their respective platforms, but
+they will both appear in documentation.
index a13a4475ef01cd270bdac96798ffd3496d082834..a9f41633f30fd11f2b5af6cc09be33efdc1912ac 100644 (file)
@@ -30,7 +30,6 @@ macro_rules! cfg_fn {
     (sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)),
     (sym::target_has_atomic, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
     (sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
     (sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)),
     (sym::target_has_atomic, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
     (sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
-    (sym::doc, sym::doc_cfg, cfg_fn!(doc_cfg)),
 ];
 
 #[derive(Debug)]
 ];
 
 #[derive(Debug)]
diff --git a/src/test/ui/cfg-rustdoc.rs b/src/test/ui/cfg-rustdoc.rs
new file mode 100644 (file)
index 0000000..a8e0c87
--- /dev/null
@@ -0,0 +1,6 @@
+#[cfg(rustdoc)]
+pub struct Foo;
+
+fn main() {
+    let f = Foo; //~ ERROR
+}
diff --git a/src/test/ui/cfg-rustdoc.stderr b/src/test/ui/cfg-rustdoc.stderr
new file mode 100644 (file)
index 0000000..c687d18
--- /dev/null
@@ -0,0 +1,9 @@
+error[E0425]: cannot find value `Foo` in this scope
+  --> $DIR/cfg-rustdoc.rs:5:13
+   |
+LL |     let f = Foo;
+   |             ^^^ not found in this scope
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/feature-gates/feature-gate-doc_cfg-cfg-rustdoc.rs b/src/test/ui/feature-gates/feature-gate-doc_cfg-cfg-rustdoc.rs
deleted file mode 100644 (file)
index 9830503..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#[cfg(doc)] //~ ERROR: `cfg(doc)` is experimental and subject to change
-pub struct SomeStruct;
-
-fn main() {}
diff --git a/src/test/ui/feature-gates/feature-gate-doc_cfg-cfg-rustdoc.stderr b/src/test/ui/feature-gates/feature-gate-doc_cfg-cfg-rustdoc.stderr
deleted file mode 100644 (file)
index 26a1f4d..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-error[E0658]: `cfg(doc)` is experimental and subject to change
-  --> $DIR/feature-gate-doc_cfg-cfg-rustdoc.rs:1:7
-   |
-LL | #[cfg(doc)]
-   |       ^^^
-   |
-   = note: for more information, see https://github.com/rust-lang/rust/issues/43781
-   = help: add `#![feature(doc_cfg)]` to the crate attributes to enable
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0658`.