Rollup merge of #79623 - jyn514:ident, r=GuillaumeGomez
Pass around Symbols instead of Idents in doctree The span was unused. Vaguely related to https://github.com/rust-lang/rust/pull/78082 - currently working on converting `visit_ast` to use `hir::intravisit` and this makes that a little easier. r? ``@GuillaumeGomez``
This commit is contained in:
commit
14895ea78b
@ -1974,16 +1974,13 @@ impl Clean<BareFunctionDecl> for hir::BareFnTy<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Ident>) {
|
impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
|
||||||
fn clean(&self, cx: &DocContext<'_>) -> Vec<Item> {
|
fn clean(&self, cx: &DocContext<'_>) -> Vec<Item> {
|
||||||
use hir::ItemKind;
|
use hir::ItemKind;
|
||||||
|
|
||||||
let (item, renamed) = self;
|
let (item, renamed) = self;
|
||||||
let def_id = cx.tcx.hir().local_def_id(item.hir_id).to_def_id();
|
let def_id = cx.tcx.hir().local_def_id(item.hir_id).to_def_id();
|
||||||
let mut name = match renamed {
|
let mut name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id));
|
||||||
Some(ident) => ident.name,
|
|
||||||
None => cx.tcx.hir().name(item.hir_id),
|
|
||||||
};
|
|
||||||
cx.with_param_env(def_id, || {
|
cx.with_param_env(def_id, || {
|
||||||
let kind = match item.kind {
|
let kind = match item.kind {
|
||||||
ItemKind::Static(ty, mutability, body_id) => StaticItem(Static {
|
ItemKind::Static(ty, mutability, body_id) => StaticItem(Static {
|
||||||
@ -2276,7 +2273,7 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Ident>) {
|
impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Symbol>) {
|
||||||
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
||||||
let (item, renamed) = self;
|
let (item, renamed) = self;
|
||||||
cx.with_param_env(cx.tcx.hir().local_def_id(item.hir_id).to_def_id(), || {
|
cx.with_param_env(cx.tcx.hir().local_def_id(item.hir_id).to_def_id(), || {
|
||||||
@ -2310,7 +2307,7 @@ impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Ident>) {
|
|||||||
|
|
||||||
Item::from_hir_id_and_parts(
|
Item::from_hir_id_and_parts(
|
||||||
item.hir_id,
|
item.hir_id,
|
||||||
Some(renamed.unwrap_or(item.ident).name),
|
Some(renamed.unwrap_or(item.ident.name)),
|
||||||
kind,
|
kind,
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
@ -2318,10 +2315,10 @@ impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Ident>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clean<Item> for (&hir::MacroDef<'_>, Option<Ident>) {
|
impl Clean<Item> for (&hir::MacroDef<'_>, Option<Symbol>) {
|
||||||
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
fn clean(&self, cx: &DocContext<'_>) -> Item {
|
||||||
let (item, renamed) = self;
|
let (item, renamed) = self;
|
||||||
let name = renamed.unwrap_or(item.ident).name;
|
let name = renamed.unwrap_or(item.ident.name);
|
||||||
let tts = item.ast.body.inner_tokens().trees().collect::<Vec<_>>();
|
let tts = item.ast.body.inner_tokens().trees().collect::<Vec<_>>();
|
||||||
// Extract the spans of all matchers. They represent the "interface" of the macro.
|
// Extract the spans of all matchers. They represent the "interface" of the macro.
|
||||||
let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect::<Vec<_>>();
|
let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect::<Vec<_>>();
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
crate use self::StructType::*;
|
crate use self::StructType::*;
|
||||||
|
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_span::{self, symbol::Ident, Span, Symbol};
|
use rustc_span::{self, Span, Symbol};
|
||||||
|
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
|
||||||
@ -16,9 +16,9 @@ crate struct Module<'hir> {
|
|||||||
crate mods: Vec<Module<'hir>>,
|
crate mods: Vec<Module<'hir>>,
|
||||||
crate id: hir::HirId,
|
crate id: hir::HirId,
|
||||||
// (item, renamed)
|
// (item, renamed)
|
||||||
crate items: Vec<(&'hir hir::Item<'hir>, Option<Ident>)>,
|
crate items: Vec<(&'hir hir::Item<'hir>, Option<Symbol>)>,
|
||||||
crate foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Ident>)>,
|
crate foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Symbol>)>,
|
||||||
crate macros: Vec<(&'hir hir::MacroDef<'hir>, Option<Ident>)>,
|
crate macros: Vec<(&'hir hir::MacroDef<'hir>, Option<Symbol>)>,
|
||||||
crate is_crate: bool,
|
crate is_crate: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ 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::source_map::Spanned;
|
use rustc_span::source_map::Spanned;
|
||||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
use rustc_span::symbol::{kw, sym, Symbol};
|
||||||
use rustc_span::{self, Span};
|
use rustc_span::{self, Span};
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
@ -116,7 +116,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
id: hir::HirId,
|
id: hir::HirId,
|
||||||
res: Res,
|
res: Res,
|
||||||
renamed: Option<Ident>,
|
renamed: Option<Symbol>,
|
||||||
glob: bool,
|
glob: bool,
|
||||||
om: &mut Module<'tcx>,
|
om: &mut Module<'tcx>,
|
||||||
please_inline: bool,
|
please_inline: bool,
|
||||||
@ -226,11 +226,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||||||
fn visit_item(
|
fn visit_item(
|
||||||
&mut self,
|
&mut self,
|
||||||
item: &'tcx hir::Item<'_>,
|
item: &'tcx hir::Item<'_>,
|
||||||
renamed: Option<Ident>,
|
renamed: Option<Symbol>,
|
||||||
om: &mut Module<'tcx>,
|
om: &mut Module<'tcx>,
|
||||||
) {
|
) {
|
||||||
debug!("visiting item {:?}", item);
|
debug!("visiting item {:?}", item);
|
||||||
let ident = renamed.unwrap_or(item.ident);
|
let name = renamed.unwrap_or(item.ident.name);
|
||||||
|
|
||||||
if item.vis.node.is_pub() {
|
if item.vis.node.is_pub() {
|
||||||
let def_id = self.cx.tcx.hir().local_def_id(item.hir_id);
|
let def_id = self.cx.tcx.hir().local_def_id(item.hir_id);
|
||||||
@ -266,7 +266,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
});
|
});
|
||||||
let ident = if is_glob { None } else { Some(ident) };
|
let ident = if is_glob { None } else { Some(name) };
|
||||||
if self.maybe_inline_local(
|
if self.maybe_inline_local(
|
||||||
item.hir_id,
|
item.hir_id,
|
||||||
path.res,
|
path.res,
|
||||||
@ -280,7 +280,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
om.imports.push(Import {
|
om.imports.push(Import {
|
||||||
name: ident.name,
|
name,
|
||||||
id: item.hir_id,
|
id: item.hir_id,
|
||||||
vis: &item.vis,
|
vis: &item.vis,
|
||||||
attrs: &item.attrs,
|
attrs: &item.attrs,
|
||||||
@ -296,7 +296,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||||||
&item.vis,
|
&item.vis,
|
||||||
item.hir_id,
|
item.hir_id,
|
||||||
m,
|
m,
|
||||||
Some(ident.name),
|
Some(name),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
hir::ItemKind::Fn(..)
|
hir::ItemKind::Fn(..)
|
||||||
@ -312,7 +312,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||||||
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 ident.name != kw::Underscore {
|
if name != kw::Underscore {
|
||||||
om.items.push((item, renamed));
|
om.items.push((item, renamed));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -329,7 +329,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||||||
fn visit_foreign_item(
|
fn visit_foreign_item(
|
||||||
&mut self,
|
&mut self,
|
||||||
item: &'tcx hir::ForeignItem<'_>,
|
item: &'tcx hir::ForeignItem<'_>,
|
||||||
renamed: Option<Ident>,
|
renamed: Option<Symbol>,
|
||||||
om: &mut Module<'tcx>,
|
om: &mut Module<'tcx>,
|
||||||
) {
|
) {
|
||||||
// If inlining we only want to include public functions.
|
// If inlining we only want to include public functions.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user