cleanup
This commit is contained in:
parent
e8dd5df69b
commit
611866f3cf
@ -152,9 +152,9 @@ pub trait Resolver {
|
|||||||
/// This should only return `None` during testing.
|
/// This should only return `None` during testing.
|
||||||
fn definitions(&mut self) -> &mut Definitions;
|
fn definitions(&mut self) -> &mut Definitions;
|
||||||
|
|
||||||
/// Given suffix ["b","c","d"], returns path `::cratename::b::c::d` when
|
/// Given suffix ["b","c","d"], creates a HIR path for `[::crate_root]::b::c::d` and resolves
|
||||||
/// The path is also resolved according to `is_value`.
|
/// it based on `is_value`.
|
||||||
fn std_path(&mut self, span: Span, crate_root: Option<&str>,
|
fn resolve_str_path(&mut self, span: Span, crate_root: Option<&str>,
|
||||||
components: &[&str], is_value: bool) -> hir::Path {
|
components: &[&str], is_value: bool) -> hir::Path {
|
||||||
let mut path = hir::Path {
|
let mut path = hir::Path {
|
||||||
span,
|
span,
|
||||||
@ -3641,7 +3641,7 @@ impl<'a> LoweringContext<'a> {
|
|||||||
/// `fld.cx.use_std`, and `::core::b::c::d` otherwise.
|
/// `fld.cx.use_std`, and `::core::b::c::d` otherwise.
|
||||||
/// The path is also resolved according to `is_value`.
|
/// The path is also resolved according to `is_value`.
|
||||||
fn std_path(&mut self, span: Span, components: &[&str], is_value: bool) -> hir::Path {
|
fn std_path(&mut self, span: Span, components: &[&str], is_value: bool) -> hir::Path {
|
||||||
self.resolver.std_path(span, self.crate_root, components, is_value)
|
self.resolver.resolve_str_path(span, self.crate_root, components, is_value)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn signal_block_expr(&mut self,
|
fn signal_block_expr(&mut self,
|
||||||
|
@ -576,8 +576,8 @@ pub struct InnerExpansionResult<'a> {
|
|||||||
/// standard library and prelude, and name resolution.
|
/// standard library and prelude, and name resolution.
|
||||||
///
|
///
|
||||||
/// Returns `None` if we're aborting after handling -W help.
|
/// Returns `None` if we're aborting after handling -W help.
|
||||||
pub fn phase_2_configure_and_expand<'a, F>(sess: &'a Session,
|
pub fn phase_2_configure_and_expand<F>(sess: &Session,
|
||||||
cstore: &'a CStore,
|
cstore: &CStore,
|
||||||
krate: ast::Crate,
|
krate: ast::Crate,
|
||||||
registry: Option<Registry>,
|
registry: Option<Registry>,
|
||||||
crate_name: &str,
|
crate_name: &str,
|
||||||
@ -593,8 +593,9 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &'a Session,
|
|||||||
// this back at some point.
|
// this back at some point.
|
||||||
let mut crate_loader = CrateLoader::new(sess, &cstore, &crate_name);
|
let mut crate_loader = CrateLoader::new(sess, &cstore, &crate_name);
|
||||||
let resolver_arenas = Resolver::arenas();
|
let resolver_arenas = Resolver::arenas();
|
||||||
let result = phase_2_configure_and_expand_inner(sess, cstore, krate, registry, crate_name, addl_plugins,
|
let result = phase_2_configure_and_expand_inner(sess, cstore, krate, registry, crate_name,
|
||||||
make_glob_map, &resolver_arenas, &mut crate_loader, after_expand);
|
addl_plugins, make_glob_map, &resolver_arenas,
|
||||||
|
&mut crate_loader, after_expand);
|
||||||
match result {
|
match result {
|
||||||
Ok(InnerExpansionResult {expanded_crate, resolver, hir_forest}) => {
|
Ok(InnerExpansionResult {expanded_crate, resolver, hir_forest}) => {
|
||||||
Ok(ExpansionResult {
|
Ok(ExpansionResult {
|
||||||
|
@ -127,7 +127,7 @@ pub struct Crate {
|
|||||||
pub masked_crates: FxHashSet<CrateNum>,
|
pub masked_crates: FxHashSet<CrateNum>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b, 'tcx, 'rcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'b, 'tcx, 'rcx> {
|
impl<'a, 'tcx, 'rcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx, 'rcx> {
|
||||||
fn clean(&self, cx: &DocContext) -> Crate {
|
fn clean(&self, cx: &DocContext) -> Crate {
|
||||||
use ::visit_lib::LibEmbargoVisitor;
|
use ::visit_lib::LibEmbargoVisitor;
|
||||||
|
|
||||||
@ -836,11 +836,11 @@ impl Clean<Attributes> for [ast::Attribute] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let path = {
|
let path = {
|
||||||
// This allocation could be avoided if std_path could take an iterator;
|
// This allocation could be avoided if resolve_str_path could take an iterator;
|
||||||
// but it can't because that would break object safety. This can still be
|
// but it can't because that would break object safety. This can still be
|
||||||
// fixed.
|
// fixed.
|
||||||
let components = link.split("::").skip(1).collect::<Vec<_>>();
|
let components = link.split("::").skip(1).collect::<Vec<_>>();
|
||||||
cx.resolver.borrow_mut().std_path(DUMMY_SP, None, &components, false)
|
cx.resolver.borrow_mut().resolve_str_path(DUMMY_SP, None, &components, false)
|
||||||
};
|
};
|
||||||
|
|
||||||
if path.def != Def::Err {
|
if path.def != Def::Err {
|
||||||
|
@ -269,7 +269,8 @@ impl<'a, 'b, I: Iterator<Item = Event<'a>>> Iterator for LinkReplacer<'a, 'b, I>
|
|||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let event = self.inner.next();
|
let event = self.inner.next();
|
||||||
if let Some(Event::Start(Tag::Link(dest, text))) = event {
|
if let Some(Event::Start(Tag::Link(dest, text))) = event {
|
||||||
if let Some(&(_, ref replace)) = self.links.into_iter().find(|link| &*link.0 == &*dest) {
|
if let Some(&(_, ref replace)) = self.links.into_iter().find(|link| &*link.0 == &*dest)
|
||||||
|
{
|
||||||
Some(Event::Start(Tag::Link(replace.to_owned().into(), text)))
|
Some(Event::Start(Tag::Link(replace.to_owned().into(), text)))
|
||||||
} else {
|
} else {
|
||||||
Some(Event::Start(Tag::Link(dest, text)))
|
Some(Event::Start(Tag::Link(dest, text)))
|
||||||
@ -1045,7 +1046,11 @@ impl<'a> fmt::Display for Markdown<'a> {
|
|||||||
let mut s = String::with_capacity(md.len() * 3 / 2);
|
let mut s = String::with_capacity(md.len() * 3 / 2);
|
||||||
|
|
||||||
html::push_html(&mut s,
|
html::push_html(&mut s,
|
||||||
Footnotes::new(CodeBlocks::new(LinkReplacer::new(HeadingLinks::new(p, None), links))));
|
Footnotes::new(
|
||||||
|
CodeBlocks::new(
|
||||||
|
LinkReplacer::new(
|
||||||
|
HeadingLinks::new(p, None),
|
||||||
|
links))));
|
||||||
|
|
||||||
fmt.write_str(&s)
|
fmt.write_str(&s)
|
||||||
}
|
}
|
||||||
@ -1233,6 +1238,7 @@ pub fn markdown_links(md: &str, render_type: RenderType) -> Vec<String> {
|
|||||||
hoedown_document_free(document);
|
hoedown_document_free(document);
|
||||||
|
|
||||||
hoedown_html_renderer_free(renderer);
|
hoedown_html_renderer_free(renderer);
|
||||||
|
hoedown_buffer_free(ob);
|
||||||
|
|
||||||
opaque.links.unwrap()
|
opaque.links.unwrap()
|
||||||
}
|
}
|
||||||
|
@ -1867,7 +1867,8 @@ fn render_markdown(w: &mut fmt::Formatter,
|
|||||||
prefix: &str,
|
prefix: &str,
|
||||||
scx: &SharedContext)
|
scx: &SharedContext)
|
||||||
-> fmt::Result {
|
-> fmt::Result {
|
||||||
let (hoedown_output, pulldown_output) = render_text(|ty| format!("{}", Markdown(md_text, &links, ty)));
|
let (hoedown_output, pulldown_output) =
|
||||||
|
render_text(|ty| format!("{}", Markdown(md_text, &links, ty)));
|
||||||
let mut differences = html_diff::get_differences(&pulldown_output, &hoedown_output);
|
let mut differences = html_diff::get_differences(&pulldown_output, &hoedown_output);
|
||||||
differences.retain(|s| {
|
differences.retain(|s| {
|
||||||
match *s {
|
match *s {
|
||||||
@ -1899,7 +1900,13 @@ fn document_short(w: &mut fmt::Formatter, item: &clean::Item, link: AssocItemLin
|
|||||||
} else {
|
} else {
|
||||||
format!("{}", &plain_summary_line(Some(s)))
|
format!("{}", &plain_summary_line(Some(s)))
|
||||||
};
|
};
|
||||||
render_markdown(w, &markdown, item.links(), item.source.clone(), cx.render_type, prefix, &cx.shared)?;
|
render_markdown(w,
|
||||||
|
&markdown,
|
||||||
|
item.links(),
|
||||||
|
item.source.clone(),
|
||||||
|
cx.render_type,
|
||||||
|
prefix,
|
||||||
|
&cx.shared)?;
|
||||||
} else if !prefix.is_empty() {
|
} else if !prefix.is_empty() {
|
||||||
write!(w, "<div class='docblock'>{}</div>", prefix)?;
|
write!(w, "<div class='docblock'>{}</div>", prefix)?;
|
||||||
}
|
}
|
||||||
@ -1925,7 +1932,13 @@ fn document_full(w: &mut fmt::Formatter, item: &clean::Item,
|
|||||||
cx: &Context, prefix: &str) -> fmt::Result {
|
cx: &Context, prefix: &str) -> fmt::Result {
|
||||||
if let Some(s) = cx.shared.maybe_collapsed_doc_value(item) {
|
if let Some(s) = cx.shared.maybe_collapsed_doc_value(item) {
|
||||||
debug!("Doc block: =====\n{}\n=====", s);
|
debug!("Doc block: =====\n{}\n=====", s);
|
||||||
render_markdown(w, &*s, item.links(), item.source.clone(), cx.render_type, prefix, &cx.shared)?;
|
render_markdown(w,
|
||||||
|
&*s,
|
||||||
|
item.links(),
|
||||||
|
item.source.clone(),
|
||||||
|
cx.render_type,
|
||||||
|
prefix,
|
||||||
|
&cx.shared)?;
|
||||||
} else if !prefix.is_empty() {
|
} else if !prefix.is_empty() {
|
||||||
write!(w, "<div class='docblock'>{}</div>", prefix)?;
|
write!(w, "<div class='docblock'>{}</div>", prefix)?;
|
||||||
}
|
}
|
||||||
@ -3339,7 +3352,8 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
|
|||||||
write!(w, "</span>")?;
|
write!(w, "</span>")?;
|
||||||
write!(w, "</h3>\n")?;
|
write!(w, "</h3>\n")?;
|
||||||
if let Some(ref dox) = cx.shared.maybe_collapsed_doc_value(&i.impl_item) {
|
if let Some(ref dox) = cx.shared.maybe_collapsed_doc_value(&i.impl_item) {
|
||||||
write!(w, "<div class='docblock'>{}</div>", Markdown(&*dox, &i.impl_item.links(), cx.render_type))?;
|
write!(w, "<div class='docblock'>{}</div>",
|
||||||
|
Markdown(&*dox, &i.impl_item.links(), cx.render_type))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
||||||
html_root_url = "https://doc.rust-lang.org/nightly/",
|
html_root_url = "https://doc.rust-lang.org/nightly/",
|
||||||
html_playground_url = "https://play.rust-lang.org/")]
|
html_playground_url = "https://play.rust-lang.org/")]
|
||||||
|
#![deny(warnings)]
|
||||||
|
|
||||||
#![feature(ascii_ctype)]
|
#![feature(ascii_ctype)]
|
||||||
#![feature(rustc_private)]
|
#![feature(rustc_private)]
|
||||||
|
@ -40,11 +40,11 @@ use doctree::*;
|
|||||||
// also, is there some reason that this doesn't use the 'visit'
|
// also, is there some reason that this doesn't use the 'visit'
|
||||||
// framework from syntax?
|
// framework from syntax?
|
||||||
|
|
||||||
pub struct RustdocVisitor<'a, 'b: 'a, 'tcx: 'b, 'rcx: 'b> {
|
pub struct RustdocVisitor<'a, 'tcx: 'a, 'rcx: 'a> {
|
||||||
cstore: &'a CrateStore,
|
cstore: &'a CrateStore,
|
||||||
pub module: Module,
|
pub module: Module,
|
||||||
pub attrs: hir::HirVec<ast::Attribute>,
|
pub attrs: hir::HirVec<ast::Attribute>,
|
||||||
pub cx: &'a core::DocContext<'b, 'tcx, 'rcx>,
|
pub cx: &'a core::DocContext<'a, 'tcx, 'rcx>,
|
||||||
view_item_stack: FxHashSet<ast::NodeId>,
|
view_item_stack: FxHashSet<ast::NodeId>,
|
||||||
inlining: bool,
|
inlining: bool,
|
||||||
/// Is the current module and all of its parents public?
|
/// Is the current module and all of its parents public?
|
||||||
@ -52,9 +52,9 @@ pub struct RustdocVisitor<'a, 'b: 'a, 'tcx: 'b, 'rcx: 'b> {
|
|||||||
reexported_macros: FxHashSet<DefId>,
|
reexported_macros: FxHashSet<DefId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b, 'tcx, 'rcx> RustdocVisitor<'a, 'b, 'tcx, 'rcx> {
|
impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
|
||||||
pub fn new(cstore: &'a CrateStore,
|
pub fn new(cstore: &'a CrateStore,
|
||||||
cx: &'a core::DocContext<'b, 'tcx, 'rcx>) -> RustdocVisitor<'a, 'b, 'tcx, 'rcx> {
|
cx: &'a core::DocContext<'a, 'tcx, 'rcx>) -> RustdocVisitor<'a, 'tcx, 'rcx> {
|
||||||
// If the root is re-exported, terminate all recursion.
|
// If the root is re-exported, terminate all recursion.
|
||||||
let mut stack = FxHashSet();
|
let mut stack = FxHashSet();
|
||||||
stack.insert(ast::CRATE_NODE_ID);
|
stack.insert(ast::CRATE_NODE_ID);
|
||||||
|
@ -22,8 +22,8 @@ use clean::{AttributesExt, NestedAttributesExt};
|
|||||||
|
|
||||||
/// Similar to `librustc_privacy::EmbargoVisitor`, but also takes
|
/// Similar to `librustc_privacy::EmbargoVisitor`, but also takes
|
||||||
/// specific rustdoc annotations into account (i.e. `doc(hidden)`)
|
/// specific rustdoc annotations into account (i.e. `doc(hidden)`)
|
||||||
pub struct LibEmbargoVisitor<'a, 'b: 'a, 'tcx: 'b, 'rcx: 'b> {
|
pub struct LibEmbargoVisitor<'a, 'tcx: 'a, 'rcx: 'a> {
|
||||||
cx: &'a ::core::DocContext<'b, 'tcx, 'rcx>,
|
cx: &'a ::core::DocContext<'a, 'tcx, 'rcx>,
|
||||||
// Accessibility levels for reachable nodes
|
// Accessibility levels for reachable nodes
|
||||||
access_levels: RefMut<'a, AccessLevels<DefId>>,
|
access_levels: RefMut<'a, AccessLevels<DefId>>,
|
||||||
// Previous accessibility level, None means unreachable
|
// Previous accessibility level, None means unreachable
|
||||||
@ -32,8 +32,8 @@ pub struct LibEmbargoVisitor<'a, 'b: 'a, 'tcx: 'b, 'rcx: 'b> {
|
|||||||
visited_mods: FxHashSet<DefId>,
|
visited_mods: FxHashSet<DefId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b, 'tcx, 'rcx> LibEmbargoVisitor<'a, 'b, 'tcx, 'rcx> {
|
impl<'a, 'tcx, 'rcx> LibEmbargoVisitor<'a, 'tcx, 'rcx> {
|
||||||
pub fn new(cx: &'a ::core::DocContext<'b, 'tcx, 'rcx>) -> LibEmbargoVisitor<'a, 'b, 'tcx, 'rcx> {
|
pub fn new(cx: &'a ::core::DocContext<'a, 'tcx, 'rcx>) -> LibEmbargoVisitor<'a, 'tcx, 'rcx> {
|
||||||
LibEmbargoVisitor {
|
LibEmbargoVisitor {
|
||||||
cx,
|
cx,
|
||||||
access_levels: cx.access_levels.borrow_mut(),
|
access_levels: cx.access_levels.borrow_mut(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user