Skip to content

Commit ae270f1

Browse files
committed
Update scrape-examples help, fix documentation typos
1 parent 212d03d commit ae270f1

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/librustdoc/html/render/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2957,14 +2957,15 @@ fn render_call_locations(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Ite
29572957

29582958
// The call locations are output in sequence, so that sequence needs to be determined.
29592959
// Ideally the most "relevant" examples would be shown first, but there's no general algorithm
2960-
// for determining relevance. We instead make a proxy for relevance with the following heuristics:
2960+
// for determining relevance. We instead proxy relevance with the following heuristics:
29612961
// 1. Code written to be an example is better than code not written to be an example, e.g.
2962-
// a snippet from examples/foo.rs is better than src/lib.rs. We don't know the Cargo directory
2963-
// structure in Rustdoc, so we proxy this by prioriting code that comes from a --crate-type bin.
2964-
// 2. Smaller examples are better than large examples. So we prioritize snippets that have the
2965-
// smallest line span for their enclosing item.
2966-
// 3. Finally we sort by the displayed file name, which is arbitrary but prevents the ordering
2967-
// of examples from randomly changing between Rustdoc invocations.
2962+
// a snippet from examples/foo.rs is better than src/lib.rs. We don't know the Cargo
2963+
// directory structure in Rustdoc, so we proxy this by prioritizing code that comes from
2964+
// a --crate-type bin.
2965+
// 2. Smaller examples are better than large examples. So we prioritize snippets that have
2966+
// the smallest number of lines in their enclosing item.
2967+
// 3. Finally we sort by the displayed file name, which is arbitrary but prevents the
2968+
// ordering of examples from randomly changing between Rustdoc invocations.
29682969
let ordered_locations = {
29692970
fn sort_criterion<'a>(
29702971
(_, call_data): &(&PathBuf, &'a CallData),

src/librustdoc/html/static/scrape-examples-help.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Rustdoc will automatically scrape examples of documented items from the `examples/` directory of a project. These examples will be included within the generated documentation for that item. For example, if your library contains a public function:
1+
Rustdoc will automatically scrape examples of documented items from a project's source code. These examples will be included within the generated documentation for that item. For example, if your library contains a public function:
22

33
```rust
44
// src/lib.rs
@@ -16,6 +16,7 @@ fn main() {
1616

1717
Then this code snippet will be included in the documentation for `a_func`.
1818

19+
1920
## How to read scraped examples
2021

2122
Scraped examples are shown as blocks of code from a given file. The relevant item will be highlighted. If the file is larger than a couple lines, only a small window will be shown which you can expand by clicking &varr; in the top-right. If a file contains multiple instances of an item, you can use the &pr; and &sc; buttons to toggle through each instance.
@@ -25,7 +26,7 @@ If there is more than one file that contains examples, then you should click "Mo
2526

2627
## How Rustdoc scrapes examples
2728

28-
When you run `cargo doc`, Rustdoc will analyze all the crates that match Cargo's `--examples` filter for instances of items that occur in the crates being documented. Then Rustdoc will include the source code of these instances in the generated documentation.
29+
When you run `cargo doc -Zunstable-options -Zrustdoc-scrape-examples`, Rustdoc will analyze all the documented crates for uses of documented items. Then Rustdoc will include the source code of these instances in the generated documentation.
2930

3031
Rustdoc has a few techniques to ensure this doesn't overwhelm documentation readers, and that it doesn't blow up the page size:
3132

0 commit comments

Comments
 (0)