Improve code readability
This commit is contained in:
parent
3623613dc7
commit
9f70bdcbc8
2 changed files with 23 additions and 15 deletions
|
@ -138,7 +138,7 @@ pub(super) fn write_shared(
|
||||||
Ok((ret, krates))
|
Ok((ret, krates))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read a file and return all lines that match the <code>"{crate}":{data},\</code> format,
|
/// Read a file and return all lines that match the <code>"{crate}":{data},\ </code> format,
|
||||||
/// and return a tuple `(Vec<DataString>, Vec<CrateNameString>)`.
|
/// and return a tuple `(Vec<DataString>, Vec<CrateNameString>)`.
|
||||||
///
|
///
|
||||||
/// This forms the payload of files that look like this:
|
/// This forms the payload of files that look like this:
|
||||||
|
|
|
@ -192,6 +192,16 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn add_to_current_mod(
|
||||||
|
&mut self,
|
||||||
|
item: &'tcx hir::Item<'_>,
|
||||||
|
renamed: Option<Symbol>,
|
||||||
|
parent_id: Option<hir::HirId>,
|
||||||
|
) {
|
||||||
|
self.modules.last_mut().unwrap().items.push((item, renamed, parent_id))
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_item_inner(
|
fn visit_item_inner(
|
||||||
&mut self,
|
&mut self,
|
||||||
item: &'tcx hir::Item<'_>,
|
item: &'tcx hir::Item<'_>,
|
||||||
|
@ -253,7 +263,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.modules.last_mut().unwrap().items.push((item, renamed, parent_id));
|
self.add_to_current_mod(item, renamed, parent_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::ItemKind::Macro(ref macro_def, _) => {
|
hir::ItemKind::Macro(ref macro_def, _) => {
|
||||||
|
@ -273,7 +283,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
let nonexported = !tcx.has_attr(def_id, sym::macro_export);
|
let nonexported = !tcx.has_attr(def_id, sym::macro_export);
|
||||||
|
|
||||||
if is_macro_2_0 || nonexported || self.inlining {
|
if is_macro_2_0 || nonexported || self.inlining {
|
||||||
self.modules.last_mut().unwrap().items.push((item, renamed, None));
|
self.add_to_current_mod(item, renamed, None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::ItemKind::Mod(ref m) => {
|
hir::ItemKind::Mod(ref m) => {
|
||||||
|
@ -289,20 +299,20 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
| hir::ItemKind::Static(..)
|
| hir::ItemKind::Static(..)
|
||||||
| hir::ItemKind::Trait(..)
|
| hir::ItemKind::Trait(..)
|
||||||
| hir::ItemKind::TraitAlias(..) => {
|
| hir::ItemKind::TraitAlias(..) => {
|
||||||
self.modules.last_mut().unwrap().items.push((item, renamed, parent_id))
|
self.add_to_current_mod(item, renamed, parent_id);
|
||||||
}
|
}
|
||||||
hir::ItemKind::Const(..) => {
|
hir::ItemKind::Const(..) => {
|
||||||
// Underscore constants do not correspond to a nameable item and
|
// Underscore constants do not correspond to a nameable item and
|
||||||
// so are never useful in documentation.
|
// so are never useful in documentation.
|
||||||
if name != kw::Underscore {
|
if name != kw::Underscore {
|
||||||
self.modules.last_mut().unwrap().items.push((item, renamed, parent_id));
|
self.add_to_current_mod(item, renamed, parent_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::ItemKind::Impl(impl_) => {
|
hir::ItemKind::Impl(impl_) => {
|
||||||
// Don't duplicate impls when inlining or if it's implementing a trait, we'll pick
|
// Don't duplicate impls when inlining or if it's implementing a trait, we'll pick
|
||||||
// them up regardless of where they're located.
|
// them up regardless of where they're located.
|
||||||
if !self.inlining && impl_.of_trait.is_none() {
|
if !self.inlining && impl_.of_trait.is_none() {
|
||||||
self.modules.last_mut().unwrap().items.push((item, None, None));
|
self.add_to_current_mod(item, None, None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,15 +349,13 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
// macro in the same module.
|
// macro in the same module.
|
||||||
let mut inserted = FxHashSet::default();
|
let mut inserted = FxHashSet::default();
|
||||||
for export in self.cx.tcx.module_reexports(CRATE_DEF_ID).unwrap_or(&[]) {
|
for export in self.cx.tcx.module_reexports(CRATE_DEF_ID).unwrap_or(&[]) {
|
||||||
if let Res::Def(DefKind::Macro(_), def_id) = export.res {
|
if let Res::Def(DefKind::Macro(_), def_id) = export.res &&
|
||||||
if let Some(local_def_id) = def_id.as_local() {
|
let Some(local_def_id) = def_id.as_local() &&
|
||||||
if self.cx.tcx.has_attr(def_id, sym::macro_export) {
|
self.cx.tcx.has_attr(def_id, sym::macro_export) &&
|
||||||
if inserted.insert(def_id) {
|
inserted.insert(def_id)
|
||||||
let item = self.cx.tcx.hir().expect_item(local_def_id);
|
{
|
||||||
top_level_module.items.push((item, None, None));
|
let item = self.cx.tcx.hir().expect_item(local_def_id);
|
||||||
}
|
top_level_module.items.push((item, None, None));
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue