You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/doc/rustdoc/src/unstable-features.md
+20-22Lines changed: 20 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -867,26 +867,40 @@ In this case, `#[cfg(feature = "linux")]`, `#[cfg(feature = "something")]`, `#[c
867
867
```rust,ignore (nightly)
868
868
#[doc(auto_cfg(
869
869
hide(feature, values("something")),
870
-
hide(target_os, values("linux"))))]
870
+
hide(target_os, values("linux")),
871
+
))]
872
+
```
873
+
874
+
Now, only `#[cfg(feature = "something")]` and `#[cfg(target_os = "linux")]` will be hidden. If you want to hide a key and all its values, you can use `any()`:
875
+
876
+
```rust,ignore (nightly)
877
+
#[doc(auto_cfg(
878
+
hide(feature, values(any())),
879
+
))]
871
880
```
872
881
873
-
Now, only `#[cfg(feature = "something")]` and `#[cfg(target_os = "linux")]` will be hidden. If you want to hide all values of a key, you can use `any()`:
882
+
If you want to hide only when there is no value you can use `none()`:
874
883
875
884
```rust,ignore (nightly)
876
-
#[doc(auto_cfg(hide(feature, values(any()))))]
885
+
#[doc(auto_cfg(
886
+
hide(feature, values("something", none())),
887
+
))]
877
888
```
878
889
879
-
If you want to hide when there is no value you can use `none()`:
890
+
So now, if you want to forbid all values for a key, but allow the key itself, you can do:
hide(feature, values(any())), // We completely hide "feature".
895
+
show(feature), // We show again "feature" (but not any value).
896
+
))]
883
897
```
884
898
885
899
If the previous example, both `#[cfg(feature)]` and `#[cfg(feature = "something")]` will be hidden.
886
900
887
901
Rustdoc currently hides `test`, `doc` and `doctest` attributes by default and reserves the right to change the list of "hidden by default" attributes.
888
902
889
-
The attribute accepts only a list of identifiers or key/value items. So you can write:
903
+
The attribute accepts only a list of identifiers and `values()`. So you can write:
890
904
891
905
```rust,ignore (nightly)
892
906
#[doc(auto_cfg(
@@ -916,14 +930,6 @@ However, it only impacts the `unix` cfg, not the feature:
916
930
#[cfg(feature = "unix")] // `feature = "unix"` is displayed
917
931
```
918
932
919
-
If `cfg_auto(show(...))` and `cfg_auto(hide(...))` are used to show/hide a same `cfg` on a same item, it'll emit an error. Example:
920
-
921
-
```rust,ignore (nightly)
922
-
#[doc(auto_cfg(hide(unix)))]
923
-
#[doc(auto_cfg(show(unix)))] // Error!
924
-
pub fn foo() {}
925
-
```
926
-
927
933
Using this attribute will re-enable `auto_cfg` if it was disabled at this location:
928
934
929
935
```rust,ignore (nightly)
@@ -941,14 +947,6 @@ pub mod module {
941
947
}
942
948
```
943
949
944
-
However, using `doc(auto_cfg = ...)` and `doc(auto_cfg(...))` on the same item will emit an error:
945
-
946
-
```rust,ignore (nightly)
947
-
#[doc(auto_cfg = false)]
948
-
#[doc(auto_cfg(hide(unix)))] // error
949
-
pub fn foo() {}
950
-
```
951
-
952
950
The reason behind this is that `doc(auto_cfg = ...)` enables or disables the feature, whereas `doc(auto_cfg(...))` enables it unconditionally, making the first attribute to appear useless as it will be overidden by the next `doc(auto_cfg)` attribute.
0 commit comments