Skip to content

Commit 5584c79

Browse files
committed
Update to latest rustc and rustdoc styles
1 parent ed8e12f commit 5584c79

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

src/doc/rustdoc/src/unstable-features.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,3 +455,17 @@ Calculating code examples follows these rules:
455455
* static
456456
* typedef
457457
2. If one of the previously listed items has a code example, then it'll be counted.
458+
459+
### `--with-examples`: include examples of uses of items as documentation
460+
461+
This option, combined with `--scrape-examples-target-crate` and `--scrape-examples-output-path`, is used to implement the functionality in [RFC #3123](https://github.com/rust-lang/rfcs/pull/3123). Uses of an item (currently functions / call-sites) are found in a crate and its reverse-dependencies, and then the uses are included as documentation for that item. This feature is intended to be used via `cargo doc --scrape-examples`, but the rustdoc-only workflow looks like:
462+
463+
```bash
464+
$ rustdoc examples/ex.rs -Z unstable-options \
465+
--extern foobar=target/deps/libfoobar.rmeta
466+
--scrape-examples-target-crate foobar \
467+
--scrape-examples-output-path output.calls
468+
$ rustdoc src/lib.rs -Z unstable-options --with-examples output.calls
469+
```
470+
471+
First, the library must be checked to generate an `rmeta`. Then a reverse-dependency like `examples/ex.rs` is given to rustdoc with the target crate being documented (`foobar`) and a path to output the calls (`output.calls`). Then, the generated calls file can be passed via `--with-examples` to the subsequent documentation of `foobar`.

src/librustdoc/html/render/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ use crate::html::format::{
7272
href, print_abi_with_space, print_constness_with_space, print_default_space,
7373
print_generic_bounds, print_where_clause, Buffer, HrefError, PrintWithSpace,
7474
};
75-
use crate::html::markdown::{HeadingOffset, Markdown, MarkdownHtml, MarkdownSummaryLine};
7675
use crate::html::highlight;
76+
use crate::html::markdown::{HeadingOffset, Markdown, MarkdownHtml, MarkdownSummaryLine};
7777
use crate::html::sources;
7878
use crate::scrape_examples::CallData;
7979

@@ -2479,9 +2479,10 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, def_id: DefId, item:
24792479
write!(
24802480
w,
24812481
"<div class=\"docblock scraped-example-list\">\
2482-
<h1 id=\"scraped-examples\" class=\"small-section-header\">\
2482+
<span></span>
2483+
<h5 id=\"scraped-examples\" class=\"section-header\">\
24832484
<a href=\"#{}\">Examples found in repository</a>\
2484-
</h1>",
2485+
</h5>",
24852486
id
24862487
);
24872488

src/librustdoc/html/static/css/rustdoc.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,6 +2071,10 @@ details.undocumented[open] > summary::before {
20712071
background: #f6fdb0;
20722072
}
20732073

2074+
.more-examples-toggle {
2075+
margin-top: 10px;
2076+
}
2077+
20742078
.more-examples-toggle summary {
20752079
color: #999;
20762080
font-family: 'Fira Sans';
@@ -2106,10 +2110,6 @@ details.undocumented[open] > summary::before {
21062110
height: 100%;
21072111
}
21082112

2109-
h1 + .scraped-example {
2110-
margin-bottom: 10px;
2111-
}
2112-
21132113
.more-scraped-examples .scraped-example {
21142114
margin-bottom: 20px;
21152115
}

src/librustdoc/scrape_examples.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ crate fn run(
216216
// Run call-finder on all items
217217
let mut calls = FxHashMap::default();
218218
let mut finder = FindCalls { calls: &mut calls, tcx, map: tcx.hir(), cx, target_crates };
219-
tcx.hir().krate().visit_all_item_likes(&mut finder.as_deep_visitor());
219+
tcx.hir().visit_all_item_likes(&mut finder.as_deep_visitor());
220220

221221
// Save output to provided path
222222
let mut encoder = FileEncoder::new(options.output_path).map_err(|e| e.to_string())?;

0 commit comments

Comments
 (0)