Skip to content

Commit 920cec4

Browse files
committed
Slight edits from lcnr's review
1 parent e6e11d7 commit 920cec4

File tree

4 files changed

+133
-3
lines changed

4 files changed

+133
-3
lines changed

linkcheck.sh

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/bin/sh
2+
#
3+
# This is a script that can be used in each book's CI to validate links using
4+
# the same tool as rust-lang/rust.
5+
#
6+
# This requires the rust-docs rustup component to be installed in the nightly
7+
# toolchain.
8+
#
9+
# Usage:
10+
# ./linkcheck.sh <name-of-book>
11+
#
12+
# Options:
13+
#
14+
# -i "Iterative" mode. The script will not clean up after it is done so
15+
# you can inspect the result, and re-run more quickly.
16+
#
17+
# --all Check all books. This can help make sure you don't break links
18+
# from other books into your book.
19+
#
20+
# --path <book-path>
21+
# Path to the root directory for the book. Default to the current
22+
# working directory if omitted.
23+
24+
set -e
25+
26+
html_dir="$(rustc +nightly --print sysroot)/share/doc/rust/html"
27+
28+
if [ ! -d "$html_dir" ]
29+
then
30+
echo "HTML docs are missing from sysroot: $html_dir"
31+
echo "Make sure the nightly rust-docs rustup component is installed."
32+
exit 1
33+
fi
34+
35+
# Avoid failure caused by newer mdbook.
36+
export MDBOOK_OUTPUT__HTML__INPUT_404=""
37+
38+
book_name=""
39+
# Default to the current directory
40+
book_path="."
41+
# Iterative will avoid cleaning up, so you can quickly run it repeatedly.
42+
iterative=0
43+
# If "1", test all books, else only this book.
44+
all_books=0
45+
46+
while [ "$1" != "" ]
47+
do
48+
case "$1" in
49+
-i)
50+
iterative=1
51+
;;
52+
--all)
53+
all_books=1
54+
;;
55+
--path)
56+
book_path="${2:-.}"
57+
shift
58+
;;
59+
*)
60+
if [ -n "$book_name" ]
61+
then
62+
echo "only one argument allowed"
63+
exit 1
64+
fi
65+
book_name="$1"
66+
;;
67+
esac
68+
shift
69+
done
70+
71+
if [ -z "$book_name" ]
72+
then
73+
echo "usage: $0 <name-of-book>"
74+
exit 1
75+
fi
76+
77+
if [ ! -f "$book_path/book.toml" ] && [ ! -f "$book_path/src/SUMMARY.md" ]
78+
then
79+
echo "Run command in root directory of the book or provide a path to the book"
80+
exit 1
81+
fi
82+
83+
if [ ! -d "$html_dir/$book_name" ]
84+
then
85+
echo "book name \"$book_name\" not found in sysroot \"$html_dir\""
86+
exit 1
87+
fi
88+
89+
if [ "$iterative" = "0" ]
90+
then
91+
echo "Cleaning old directories..."
92+
rm -rf linkcheck linkchecker
93+
fi
94+
95+
if [ ! -e "linkchecker/main.rs" ] || [ "$iterative" = "0" ]
96+
then
97+
echo "Downloading linkchecker source..."
98+
nightly_hash=$(rustc +nightly -Vv | grep commit-hash | cut -f2 -d" ")
99+
url="https://raw.githubusercontent.com/rust-lang/rust"
100+
mkdir linkchecker
101+
curl -o linkchecker/Cargo.lock ${url}/${nightly_hash}/Cargo.lock
102+
curl -o linkchecker/Cargo.toml ${url}/${nightly_hash}/src/tools/linkchecker/Cargo.toml
103+
curl -o linkchecker/main.rs ${url}/${nightly_hash}/src/tools/linkchecker/main.rs
104+
fi
105+
106+
echo "Building book \"$book_name\"..."
107+
mdbook build "$book_path"
108+
109+
cp -R "$html_dir" linkcheck
110+
rm -rf "linkcheck/$book_name"
111+
cp -R "$book_path/book" "linkcheck/$book_name"
112+
113+
if [ "$all_books" = "1" ]
114+
then
115+
check_path="linkcheck"
116+
else
117+
check_path="linkcheck/$book_name"
118+
fi
119+
echo "Running linkchecker on \"$check_path\"..."
120+
cargo run --release --manifest-path=linkchecker/Cargo.toml -- "$check_path"
121+
122+
if [ "$iterative" = "0" ]
123+
then
124+
rm -rf linkcheck linkchecker
125+
fi
126+
127+
echo "Link check completed successfully!"

src/divergence.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ The following language constructs unconditonally produce a _diverging expression
1818
* [A `continue` expression](./expressions/loop-expr.md#r-expr.loop.continue.type)
1919
* [A `return` expression](./expressions/return-expr.md#r-expr.return.type)
2020
* [A `match` expression with no arms](./expressions/match-expr.md#r-expr.match.type.diverging.empty)
21-
* [A `block` expression that it itself is diverging.](../expressions/block-expr.md#r-expr.block.type.diverging)
21+
* [A `block` expression that it itself is diverging.](./expressions/block-expr.md#r-expr.block.type.diverging)
2222

2323
r[divergence.diverging-expressions.conditional]
2424
In a control flow expression, if all arms diverge, then the entire expression also diverges.
2525

26+
r[divergence.diverging-expressions.place-expressions]
27+
A place expression of the type [`!`](./types/never.md) is considering _diverging_ only if it is read from.
28+
2629
r[divergence.fallback]
2730
## Fallback
2831
If a type to be inferred is only unified with diverging expressions, then that type will be inferred to be `!`.

src/expressions/block-expr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ assert_eq!(5, five);
6161
```
6262

6363
r[expr.block.type.diverging]
64-
However, if there are any values unconditionally created within a block that are [diverging](../divergence.md), then the block itself is considered diverging.
64+
A block is itself considered to be [diverging](../divergence.md) if all reachable control flow paths contain a [diverging expression](../divergence.md#r-divergence.diverging-expressions).
6565

6666
r[expr.block.value]
6767
Blocks are always [value expressions] and evaluate the last operand in value expression context.

src/expressions/match-expr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ r[expr.match.binding-restriction]
9797
Every binding of the same name must have the same type, and have the same binding mode.
9898

9999
r[expr.match.type]
100-
The type of the overall `match` expression is the least upper bound of the individual match arms.
100+
The type of the overall `match` expression is the [least upper bound](../type-coercions.md#r-coerce.least-upper-bound) of the individual match arms.
101101

102102
r[expr.match.type.diverging.empty]
103103
If there are no match arms, then the `match` expression is diverging and the type is [`!`](../types/never.md).

0 commit comments

Comments
 (0)