Rollup merge of #84763 - tdelabro:shrink-doctree-module, r=jyn514
shrink doctree::Module helps https://github.com/rust-lang/rust/issues/76382
This commit is contained in:
commit
e643e2ebdf
3 changed files with 14 additions and 15 deletions
|
@ -100,12 +100,13 @@ impl Clean<Item> for doctree::Module<'_> {
|
||||||
// determine if we should display the inner contents or
|
// determine if we should display the inner contents or
|
||||||
// the outer `mod` item for the source code.
|
// the outer `mod` item for the source code.
|
||||||
let span = Span::from_rustc_span({
|
let span = Span::from_rustc_span({
|
||||||
|
let where_outer = self.where_outer(cx.tcx);
|
||||||
let sm = cx.sess().source_map();
|
let sm = cx.sess().source_map();
|
||||||
let outer = sm.lookup_char_pos(self.where_outer.lo());
|
let outer = sm.lookup_char_pos(where_outer.lo());
|
||||||
let inner = sm.lookup_char_pos(self.where_inner.lo());
|
let inner = sm.lookup_char_pos(self.where_inner.lo());
|
||||||
if outer.file.start_pos == inner.file.start_pos {
|
if outer.file.start_pos == inner.file.start_pos {
|
||||||
// mod foo { ... }
|
// mod foo { ... }
|
||||||
self.where_outer
|
where_outer
|
||||||
} else {
|
} else {
|
||||||
// mod foo; (and a separate SourceFile for the contents)
|
// mod foo; (and a separate SourceFile for the contents)
|
||||||
self.where_inner
|
self.where_inner
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
//! This module is used to store stuff from Rust's AST in a more convenient
|
//! This module is used to store stuff from Rust's AST in a more convenient
|
||||||
//! manner (and with prettier names) before cleaning.
|
//! manner (and with prettier names) before cleaning.
|
||||||
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_span::{self, Span, Symbol};
|
use rustc_span::{self, Span, Symbol};
|
||||||
|
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
|
||||||
crate struct Module<'hir> {
|
crate struct Module<'hir> {
|
||||||
crate name: Symbol,
|
crate name: Symbol,
|
||||||
crate where_outer: Span,
|
|
||||||
crate where_inner: Span,
|
crate where_inner: Span,
|
||||||
crate mods: Vec<Module<'hir>>,
|
crate mods: Vec<Module<'hir>>,
|
||||||
crate id: hir::HirId,
|
crate id: hir::HirId,
|
||||||
|
@ -17,16 +17,19 @@ crate struct Module<'hir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Module<'hir> {
|
impl Module<'hir> {
|
||||||
crate fn new(name: Symbol) -> Module<'hir> {
|
crate fn new(name: Symbol, id: hir::HirId, where_inner: Span) -> Module<'hir> {
|
||||||
Module {
|
Module {
|
||||||
name,
|
name,
|
||||||
id: hir::CRATE_HIR_ID,
|
id,
|
||||||
where_outer: rustc_span::DUMMY_SP,
|
where_inner,
|
||||||
where_inner: rustc_span::DUMMY_SP,
|
|
||||||
mods: Vec::new(),
|
mods: Vec::new(),
|
||||||
items: Vec::new(),
|
items: Vec::new(),
|
||||||
foreigns: Vec::new(),
|
foreigns: Vec::new(),
|
||||||
macros: Vec::new(),
|
macros: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
crate fn where_outer(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
|
tcx.hir().span(self.id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,9 @@ use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::Node;
|
use rustc_hir::Node;
|
||||||
use rustc_middle::middle::privacy::AccessLevel;
|
use rustc_middle::middle::privacy::AccessLevel;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
|
use rustc_span;
|
||||||
use rustc_span::source_map::Spanned;
|
use rustc_span::source_map::Spanned;
|
||||||
use rustc_span::symbol::{kw, sym, Symbol};
|
use rustc_span::symbol::{kw, sym, Symbol};
|
||||||
use rustc_span::{self, Span};
|
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
|
@ -73,7 +73,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
crate fn visit(mut self, krate: &'tcx hir::Crate<'_>) -> Module<'tcx> {
|
crate fn visit(mut self, krate: &'tcx hir::Crate<'_>) -> Module<'tcx> {
|
||||||
let span = krate.item.inner;
|
let span = krate.item.inner;
|
||||||
let mut top_level_module = self.visit_mod_contents(
|
let mut top_level_module = self.visit_mod_contents(
|
||||||
span,
|
|
||||||
&Spanned { span, node: hir::VisibilityKind::Public },
|
&Spanned { span, node: hir::VisibilityKind::Public },
|
||||||
hir::CRATE_HIR_ID,
|
hir::CRATE_HIR_ID,
|
||||||
&krate.item,
|
&krate.item,
|
||||||
|
@ -129,16 +128,12 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
|
|
||||||
fn visit_mod_contents(
|
fn visit_mod_contents(
|
||||||
&mut self,
|
&mut self,
|
||||||
span: Span,
|
|
||||||
vis: &hir::Visibility<'_>,
|
vis: &hir::Visibility<'_>,
|
||||||
id: hir::HirId,
|
id: hir::HirId,
|
||||||
m: &'tcx hir::Mod<'tcx>,
|
m: &'tcx hir::Mod<'tcx>,
|
||||||
name: Symbol,
|
name: Symbol,
|
||||||
) -> Module<'tcx> {
|
) -> Module<'tcx> {
|
||||||
let mut om = Module::new(name);
|
let mut om = Module::new(name, id, m.inner);
|
||||||
om.where_outer = span;
|
|
||||||
om.where_inner = m.inner;
|
|
||||||
om.id = id;
|
|
||||||
// Keep track of if there were any private modules in the path.
|
// Keep track of if there were any private modules in the path.
|
||||||
let orig_inside_public_path = self.inside_public_path;
|
let orig_inside_public_path = self.inside_public_path;
|
||||||
self.inside_public_path &= vis.node.is_pub();
|
self.inside_public_path &= vis.node.is_pub();
|
||||||
|
@ -312,7 +307,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
om.items.push((item, renamed))
|
om.items.push((item, renamed))
|
||||||
}
|
}
|
||||||
hir::ItemKind::Mod(ref m) => {
|
hir::ItemKind::Mod(ref m) => {
|
||||||
om.mods.push(self.visit_mod_contents(item.span, &item.vis, item.hir_id(), m, name));
|
om.mods.push(self.visit_mod_contents(&item.vis, item.hir_id(), m, name));
|
||||||
}
|
}
|
||||||
hir::ItemKind::Fn(..)
|
hir::ItemKind::Fn(..)
|
||||||
| hir::ItemKind::ExternCrate(..)
|
| hir::ItemKind::ExternCrate(..)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue