提交 b412b46c 编写于 作者: J Joshua Nelson

Do the hard part first

The only bit failing was the module, so change that before removing the
`span` field.
上级 a4b62142
......@@ -487,7 +487,8 @@ fn build_module(
}
}
clean::Module { items }
let span = clean::Span::from_rustc_span(cx.tcx.def_span(did));
clean::Module { items, span }
}
crate fn print_inlined_const(tcx: TyCtxt<'_>, did: DefId) -> String {
......
......@@ -100,7 +100,7 @@ fn clean(&self, cx: &mut DocContext<'_>) -> Item {
// determine if we should display the inner contents or
// the outer `mod` item for the source code.
let span = {
let span = Span::from_rustc_span({
let sm = cx.sess().source_map();
let outer = sm.lookup_char_pos(self.where_outer.lo());
let inner = sm.lookup_char_pos(self.where_inner.lo());
......@@ -111,11 +111,14 @@ fn clean(&self, cx: &mut DocContext<'_>) -> Item {
// mod foo; (and a separate SourceFile for the contents)
self.where_inner
}
};
});
let what_rustc_thinks =
Item::from_hir_id_and_parts(self.id, Some(self.name), ModuleItem(Module { items }), cx);
Item { span: span.clean(cx), ..what_rustc_thinks }
Item::from_hir_id_and_parts(
self.id,
Some(self.name),
ModuleItem(Module { items, span }),
cx,
)
}
}
......
......@@ -232,7 +232,7 @@ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let def_id: &dyn fmt::Debug = if self.is_fake() { &"**FAKE**" } else { &self.def_id };
fmt.debug_struct("Item")
.field("source", &self.span)
.field("source", &self.span())
.field("name", &self.name)
.field("attrs", &self.attrs)
.field("kind", &self.kind)
......@@ -255,8 +255,12 @@ impl Item {
if self.is_fake() { None } else { tcx.lookup_deprecation(self.def_id) }
}
crate fn span(&self) -> Span {
if let ItemKind::ModuleItem(Module { span, .. }) = &*self.kind { *span } else { self.span }
}
crate fn attr_span(&self, _tcx: TyCtxt<'_>) -> rustc_span::Span {
crate::passes::span_of_attrs(&self.attrs).unwrap_or_else(|| self.span.inner())
crate::passes::span_of_attrs(&self.attrs).unwrap_or_else(|| self.span().inner())
}
/// Finds the `doc` attribute as a NameValue and returns the corresponding
......@@ -609,6 +613,7 @@ impl ItemKind {
#[derive(Clone, Debug)]
crate struct Module {
crate items: Vec<Item>,
crate span: Span,
}
crate struct ListAttributesIter<'a> {
......
......@@ -80,7 +80,10 @@ fn fold_item_recur(&mut self, mut item: Item) -> Item {
}
fn fold_mod(&mut self, m: Module) -> Module {
Module { items: m.items.into_iter().filter_map(|i| self.fold_item(i)).collect() }
Module {
span: m.span,
items: m.items.into_iter().filter_map(|i| self.fold_item(i)).collect(),
}
}
fn fold_crate(&mut self, mut c: Crate) -> Crate {
......
......@@ -281,15 +281,15 @@ fn build_sidebar_items(&self, m: &clean::Module) -> BTreeMap<String, Vec<NameDoc
/// may happen, for example, with externally inlined items where the source
/// of their crate documentation isn't known.
pub(super) fn src_href(&self, item: &clean::Item) -> Option<String> {
if item.span.is_dummy() {
if item.span().is_dummy() {
return None;
}
let mut root = self.root_path();
let mut path = String::new();
let cnum = item.span.cnum(self.sess());
let cnum = item.span().cnum(self.sess());
// We can safely ignore synthetic `SourceFile`s.
let file = match item.span.filename(self.sess()) {
let file = match item.span().filename(self.sess()) {
FileName::Real(ref path) => path.local_path().to_path_buf(),
_ => return None,
};
......@@ -323,8 +323,8 @@ pub(super) fn src_href(&self, item: &clean::Item) -> Option<String> {
(&*symbol, &path)
};
let loline = item.span.lo(self.sess()).line;
let hiline = item.span.hi(self.sess()).line;
let loline = item.span().lo(self.sess()).line;
let hiline = item.span().hi(self.sess()).line;
let lines =
if loline == hiline { loline.to_string() } else { format!("{}-{}", loline, hiline) };
Some(format!(
......
......@@ -1013,7 +1013,7 @@ fn item_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Mac
Some("macro"),
None,
None,
it.span.inner().edition(),
it.span().inner().edition(),
);
});
document(w, cx, it, None)
......
......@@ -41,11 +41,11 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
// then we need to render it out to the filesystem.
if self.scx.include_sources
// skip all synthetic "files"
&& item.span.filename(self.sess()).is_real()
&& item.span().filename(self.sess()).is_real()
// skip non-local files
&& item.span.cnum(self.sess()) == LOCAL_CRATE
&& item.span().cnum(self.sess()) == LOCAL_CRATE
{
let filename = item.span.filename(self.sess());
let filename = item.span().filename(self.sess());
// If it turns out that we couldn't read this file, then we probably
// can't read any of the files (generating html output from json or
// something like that), so just don't include sources for the
......
......@@ -40,7 +40,8 @@ pub(super) fn convert_item(&self, item: clean::Item) -> Option<Item> {
.iter()
.map(rustc_ast_pretty::pprust::attribute_to_string)
.collect();
let clean::Item { span, name, attrs: _, kind: _, visibility, def_id } = item;
let span = item.span();
let clean::Item { name, attrs: _, kind: _, span: _, visibility, def_id } = item;
let inner = match *item.kind {
clean::StrippedItem(_) => return None,
_ => from_clean_item(item, self.tcx),
......
......@@ -211,7 +211,7 @@ fn fold_item(&mut self, i: clean::Item) -> Option<clean::Item> {
None,
);
let filename = i.span.filename(self.ctx.sess());
let filename = i.span().filename(self.ctx.sess());
let has_doc_example = tests.found_tests != 0;
let hir_id = self.ctx.tcx.hir().local_def_id_to_hir_id(i.def_id.expect_local());
let (level, source) = self.ctx.tcx.lint_level_at_node(MISSING_DOCS, hir_id);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册