Change serialized format to use DefPathHash instead of custom String
Move test to rustdoc-ui Fix test writing to wrong directory Formatting Fix test Add FIXME Remove raw multiline strings
This commit is contained in:
parent
5c05b3c03d
commit
df5e3a6e40
7 changed files with 27 additions and 41 deletions
|
@ -258,11 +258,7 @@ impl Iterator for PeekIter<'a> {
|
|||
type Item = (TokenKind, &'a str);
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.peek_pos = 0;
|
||||
if let Some(first) = self.stored.pop_front() {
|
||||
Some(first)
|
||||
} else {
|
||||
self.iter.next()
|
||||
}
|
||||
if let Some(first) = self.stored.pop_front() { Some(first) } else { self.iter.next() }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ fn test_union_highlighting() {
|
|||
create_default_session_globals_then(|| {
|
||||
let src = include_str!("fixtures/union.rs");
|
||||
let mut html = Buffer::new();
|
||||
write_code(&mut html, src, Edition::Edition2018, None);
|
||||
write_code(&mut html, src, Edition::Edition2018, None, None);
|
||||
expect_file!["fixtures/union.html"].assert_eq(&html.into_inner());
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2465,7 +2465,7 @@ const MAX_FULL_EXAMPLES: usize = 5;
|
|||
/// Generates the HTML for example call locations generated via the --scrape-examples flag.
|
||||
fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, def_id: DefId, item: &clean::Item) {
|
||||
let tcx = cx.tcx();
|
||||
let key = crate::scrape_examples::def_id_call_key(tcx, def_id);
|
||||
let key = tcx.def_path_hash(def_id);
|
||||
let call_locations = match cx.shared.call_locations.get(&key) {
|
||||
Some(call_locations) => call_locations,
|
||||
_ => {
|
||||
|
@ -2474,13 +2474,14 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, def_id: DefId, item:
|
|||
};
|
||||
|
||||
// Generate a unique ID so users can link to this section for a given method
|
||||
// FIXME: this should use init_id_map instead of derive
|
||||
let id = cx.id_map.borrow_mut().derive("scraped-examples");
|
||||
write!(
|
||||
w,
|
||||
r##"<div class="docblock scraped-example-list">
|
||||
<h1 id="scraped-examples" class="small-section-header">
|
||||
<a href="#{}">Examples found in repository</a>
|
||||
</h1>"##,
|
||||
"<div class=\"docblock scraped-example-list\">\
|
||||
<h1 id=\"scraped-examples\" class=\"small-section-header\">\
|
||||
<a href=\"#{}\">Examples found in repository</a>\
|
||||
</h1>",
|
||||
id
|
||||
);
|
||||
|
||||
|
@ -2533,11 +2534,11 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, def_id: DefId, item:
|
|||
|
||||
write!(
|
||||
w,
|
||||
r#"<div class="scraped-example" data-locs="{locations}" data-offset="{offset}">
|
||||
<div class="scraped-example-title">
|
||||
{name} (<a href="{root}{url}" target="_blank">{line_range}</a>)
|
||||
</div>
|
||||
<div class="code-wrapper">"#,
|
||||
"<div class=\"scraped-example\" data-locs=\"{locations}\" data-offset=\"{offset}\">\
|
||||
<div class=\"scraped-example-title\">\
|
||||
{name} (<a href=\"{root}{url}\" target=\"_blank\">{line_range}</a>)\
|
||||
</div>\
|
||||
<div class=\"code-wrapper\">",
|
||||
root = cx.root_path(),
|
||||
url = call_data.url,
|
||||
name = call_data.display_name,
|
||||
|
@ -2625,14 +2626,13 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, def_id: DefId, item:
|
|||
if it.peek().is_some() {
|
||||
write!(
|
||||
w,
|
||||
r#"<details class="rustdoc-toggle more-examples-toggle">
|
||||
<summary class="hideme">
|
||||
<span>More examples</span>
|
||||
</summary>
|
||||
<div class="more-scraped-examples">
|
||||
<div class="toggle-line"><div class="toggle-line-inner"></div></div>
|
||||
<div class="more-scraped-examples-inner">
|
||||
"#
|
||||
"<details class=\"rustdoc-toggle more-examples-toggle\">\
|
||||
<summary class=\"hideme\">\
|
||||
<span>More examples</span>\
|
||||
</summary>\
|
||||
<div class=\"more-scraped-examples\">\
|
||||
<div class=\"toggle-line\"><div class=\"toggle-line-inner\"></div></div>\
|
||||
<div class=\"more-scraped-examples-inner\">"
|
||||
);
|
||||
|
||||
// Only generate inline code for MAX_FULL_EXAMPLES number of examples. Otherwise we could
|
||||
|
@ -2643,10 +2643,7 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, def_id: DefId, item:
|
|||
|
||||
// For the remaining examples, generate a <ul> containing links to the source files.
|
||||
if it.peek().is_some() {
|
||||
write!(
|
||||
w,
|
||||
r#"<div class="example-links">Additional examples can be found in:<br /><ul>"#
|
||||
);
|
||||
write!(w, r#"<div class="example-links">Additional examples can be found in:<br><ul>"#);
|
||||
it.for_each(|(_, call_data)| {
|
||||
write!(
|
||||
w,
|
||||
|
|
|
@ -22,7 +22,7 @@ use rustc_serialize::{
|
|||
};
|
||||
use rustc_session::getopts;
|
||||
use rustc_span::{
|
||||
def_id::{CrateNum, DefId},
|
||||
def_id::{CrateNum, DefPathHash},
|
||||
edition::Edition,
|
||||
BytePos, FileName, SourceFile,
|
||||
};
|
||||
|
@ -108,7 +108,7 @@ crate struct CallData {
|
|||
}
|
||||
|
||||
crate type FnCallLocations = FxHashMap<PathBuf, CallData>;
|
||||
crate type AllCallLocations = FxHashMap<String, FnCallLocations>;
|
||||
crate type AllCallLocations = FxHashMap<DefPathHash, FnCallLocations>;
|
||||
|
||||
/// Visitor for traversing a crate and finding instances of function calls.
|
||||
struct FindCalls<'a, 'tcx> {
|
||||
|
@ -119,14 +119,6 @@ struct FindCalls<'a, 'tcx> {
|
|||
calls: &'a mut AllCallLocations,
|
||||
}
|
||||
|
||||
crate fn def_id_call_key(tcx: TyCtxt<'_>, def_id: DefId) -> String {
|
||||
format!(
|
||||
"{}{}",
|
||||
tcx.crate_name(def_id.krate).to_ident_string(),
|
||||
tcx.def_path(def_id).to_string_no_crate_verbose()
|
||||
)
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for FindCalls<'a, 'tcx>
|
||||
where
|
||||
'tcx: 'a,
|
||||
|
@ -185,7 +177,7 @@ where
|
|||
CallData { locations: Vec::new(), url, display_name, edition }
|
||||
};
|
||||
|
||||
let fn_key = def_id_call_key(tcx, *def_id);
|
||||
let fn_key = tcx.def_path_hash(*def_id);
|
||||
let fn_entries = self.calls.entry(fn_key).or_default();
|
||||
|
||||
let location = CallLocation::new(tcx, span, ex.hir_id, &file);
|
||||
|
|
|
@ -7,7 +7,7 @@ all:
|
|||
$(RUSTC) src/lib.rs --crate-name foobar --crate-type lib --emit=metadata
|
||||
|
||||
# 2. scrape examples from the reverse-dependency into an ex.calls file
|
||||
$(RUSTDOC) examples/ex.rs --crate-name ex --crate-type bin \
|
||||
$(RUSTDOC) examples/ex.rs --crate-name ex --crate-type bin --output $(OUTPUT_DIR) \
|
||||
--extern foobar=$(TMPDIR)/libfoobar.rmeta \
|
||||
-Z unstable-options \
|
||||
--scrape-examples-output-path $(TMPDIR)/ex.calls \
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
// should-fail
|
||||
// compile-flags: --scrape-examples-target-crate foobar
|
2
src/test/rustdoc-ui/scrape-examples-wrong-options.stderr
Normal file
2
src/test/rustdoc-ui/scrape-examples-wrong-options.stderr
Normal file
|
@ -0,0 +1,2 @@
|
|||
error: the `-Z unstable-options` flag must also be passed to enable the flag `scrape-examples-target-crate`
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue