Skip to content

Commit 5f33dba

Browse files
committed
Slightly nicer doc-cfg replacements
1 parent 822b657 commit 5f33dba

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

documentation/apply-doc-cfg.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ echo "$PRE preprocess docs..."
5050

5151
# Enable feature in each lib.rs file.
5252
# Note: first command uses sed because it's easier, and only handful of files.
53-
find . -type f -name "lib.rs" -exec sed -i '1s/^/#![feature(doc_cfg)]\n/' {} +
53+
find . -type f -name "lib.rs" -exec sed -i '1s/^/#![cfg_attr(published_docs, feature(doc_cfg))]\n/' {} +
5454

5555
# Then do the actual replacements.
5656
# Could use \( -path "..." -o -path "..." \) to limit to certain paths.
@@ -61,14 +61,15 @@ find . -type f -name '*.rs' \
6161
| while read -r file; do
6262
# Replace #[cfg(...)] with #[doc(cfg(...))]. Do not insert a newline, in case the #[cfg] is commented-out.
6363
# shellcheck disable=SC2016
64-
$sd '(\#\[(cfg\(.+?\))\])\s*([A-Za-z]|#\[)' '$1 #[doc($2)]\n$3' "$file"
64+
$sd '(\#\[(cfg\(.+?\))\])(\s*)([A-Za-z]|#\[)' '$1 #[cfg_attr(published_docs, doc($2))]$3$4' "$file"
65+
# $sd '(\#\[(cfg\(.+?\))\])\s*([A-Za-z]|#\[)' '$1 #[doc($2)]\n$3' "$file"
6566
# ^^^^^^^^^^^^^^^^^ require that #[cfg] is followed by an identifier or a #[ attribute start.
6667
# This avoids some usages of function-local #[cfg]s, although by far not all. Others generate warnings, which is fine.
6768
done
6869

6970
if [[ "$rustfmt" == "true" ]]; then
7071
echo "$PRE Format code using rustfmt..."
71-
cargo fmt
72+
cargo fmt --all
7273
fi
7374

7475
echo "$PRE Docs post-processed."

0 commit comments

Comments
 (0)