1
Fork 0

Update to latest rustc and rustdoc styles

This commit is contained in:
Will Crichton 2021-10-06 21:43:40 -07:00
parent ed8e12fd24
commit 5584c79597
4 changed files with 23 additions and 8 deletions

View file

@ -455,3 +455,17 @@ Calculating code examples follows these rules:
* static * static
* typedef * typedef
2. If one of the previously listed items has a code example, then it'll be counted. 2. If one of the previously listed items has a code example, then it'll be counted.
### `--with-examples`: include examples of uses of items as documentation
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:
```bash
$ rustdoc examples/ex.rs -Z unstable-options \
--extern foobar=target/deps/libfoobar.rmeta
--scrape-examples-target-crate foobar \
--scrape-examples-output-path output.calls
$ rustdoc src/lib.rs -Z unstable-options --with-examples output.calls
```
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`.

View file

@ -72,8 +72,8 @@ use crate::html::format::{
href, print_abi_with_space, print_constness_with_space, print_default_space, href, print_abi_with_space, print_constness_with_space, print_default_space,
print_generic_bounds, print_where_clause, Buffer, HrefError, PrintWithSpace, print_generic_bounds, print_where_clause, Buffer, HrefError, PrintWithSpace,
}; };
use crate::html::markdown::{HeadingOffset, Markdown, MarkdownHtml, MarkdownSummaryLine};
use crate::html::highlight; use crate::html::highlight;
use crate::html::markdown::{HeadingOffset, Markdown, MarkdownHtml, MarkdownSummaryLine};
use crate::html::sources; use crate::html::sources;
use crate::scrape_examples::CallData; use crate::scrape_examples::CallData;
@ -2479,9 +2479,10 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, def_id: DefId, item:
write!( write!(
w, w,
"<div class=\"docblock scraped-example-list\">\ "<div class=\"docblock scraped-example-list\">\
<h1 id=\"scraped-examples\" class=\"small-section-header\">\ <span></span>
<h5 id=\"scraped-examples\" class=\"section-header\">\
<a href=\"#{}\">Examples found in repository</a>\ <a href=\"#{}\">Examples found in repository</a>\
</h1>", </h5>",
id id
); );

View file

@ -2071,6 +2071,10 @@ details.undocumented[open] > summary::before {
background: #f6fdb0; background: #f6fdb0;
} }
.more-examples-toggle {
margin-top: 10px;
}
.more-examples-toggle summary { .more-examples-toggle summary {
color: #999; color: #999;
font-family: 'Fira Sans'; font-family: 'Fira Sans';
@ -2106,10 +2110,6 @@ details.undocumented[open] > summary::before {
height: 100%; height: 100%;
} }
h1 + .scraped-example {
margin-bottom: 10px;
}
.more-scraped-examples .scraped-example { .more-scraped-examples .scraped-example {
margin-bottom: 20px; margin-bottom: 20px;
} }

View file

@ -216,7 +216,7 @@ crate fn run(
// Run call-finder on all items // Run call-finder on all items
let mut calls = FxHashMap::default(); let mut calls = FxHashMap::default();
let mut finder = FindCalls { calls: &mut calls, tcx, map: tcx.hir(), cx, target_crates }; let mut finder = FindCalls { calls: &mut calls, tcx, map: tcx.hir(), cx, target_crates };
tcx.hir().krate().visit_all_item_likes(&mut finder.as_deep_visitor()); tcx.hir().visit_all_item_likes(&mut finder.as_deep_visitor());
// Save output to provided path // Save output to provided path
let mut encoder = FileEncoder::new(options.output_path).map_err(|e| e.to_string())?; let mut encoder = FileEncoder::new(options.output_path).map_err(|e| e.to_string())?;