Skip to content

Commit 8b9b106

Browse files
committed
Rename clean::Item.source to span
Its type is called `clean::Span`, and also the name in the rest of rustdoc and rustc for this kind of field is `span`.
1 parent f826641 commit 8b9b106

15 files changed

+38
-34
lines changed

src/librustdoc/clean/auto_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
110110
};
111111

112112
Some(Item {
113-
source: Span::dummy(),
113+
span: Span::dummy(),
114114
name: None,
115115
attrs: Default::default(),
116116
visibility: Inherited,

src/librustdoc/clean/blanket_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
102102
.collect();
103103

104104
impls.push(Item {
105-
source: self.cx.tcx.def_span(impl_def_id).clean(self.cx),
105+
span: self.cx.tcx.def_span(impl_def_id).clean(self.cx),
106106
name: None,
107107
attrs: Default::default(),
108108
visibility: Inherited,

src/librustdoc/clean/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ fn build_module(
459459
items.push(clean::Item {
460460
name: None,
461461
attrs: box clean::Attributes::default(),
462-
source: clean::Span::dummy(),
462+
span: clean::Span::dummy(),
463463
def_id: DefId::local(CRATE_DEF_INDEX),
464464
visibility: clean::Public,
465465
kind: box clean::ImportItem(clean::Import::new_simple(

src/librustdoc/clean/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl Clean<Item> for doctree::Module<'_> {
235235
ModuleItem(Module { is_crate: self.is_crate, items }),
236236
cx,
237237
);
238-
Item { source: span.clean(cx), ..what_rustc_thinks }
238+
Item { span: span.clean(cx), ..what_rustc_thinks }
239239
}
240240
}
241241

@@ -2132,7 +2132,7 @@ fn clean_extern_crate(
21322132
vec![Item {
21332133
name: Some(name),
21342134
attrs: box attrs.clean(cx),
2135-
source: krate.span.clean(cx),
2135+
span: krate.span.clean(cx),
21362136
def_id: crate_def_id,
21372137
visibility: krate.vis.clean(cx),
21382138
kind: box ExternCrateItem { src: orig_name },

src/librustdoc/clean/types.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,19 @@ crate struct ExternalCrate {
8181
/// directly to the AST's concept of an item; it's a strict superset.
8282
#[derive(Clone)]
8383
crate struct Item {
84-
/// Stringified span
85-
crate source: Span,
86-
/// Not everything has a name. E.g., impls
84+
/// The [`Span`] of this item in the source code.
85+
crate span: Span,
86+
/// The name of this item.
87+
/// Optional because not every item has a name, e.g. impls.
8788
crate name: Option<Symbol>,
89+
/// Attributes on this item, e.g. `#[derive(...)]` or `#[inline]`.
8890
crate attrs: Box<Attributes>,
91+
/// The visibility of this item (private, `pub`, `pub(crate)`, etc.).
8992
crate visibility: Visibility,
93+
/// Information about this item that is specific to what kind of item it is.
94+
/// E.g., struct vs enum vs function.
9095
crate kind: Box<ItemKind>,
96+
/// The [`DefId`] of this item.
9197
crate def_id: DefId,
9298
}
9399

@@ -100,7 +106,7 @@ impl fmt::Debug for Item {
100106
let def_id: &dyn fmt::Debug = if self.is_fake() { &"**FAKE**" } else { &self.def_id };
101107

102108
fmt.debug_struct("Item")
103-
.field("source", &self.source)
109+
.field("source", &self.span)
104110
.field("name", &self.name)
105111
.field("attrs", &self.attrs)
106112
.field("kind", &self.kind)
@@ -165,7 +171,7 @@ impl Item {
165171
debug!("name={:?}, def_id={:?}", name, def_id);
166172

167173
// `span_if_local()` lies about functions and only gives the span of the function signature
168-
let source = def_id.as_local().map_or_else(
174+
let span = def_id.as_local().map_or_else(
169175
|| cx.tcx.def_span(def_id),
170176
|local| {
171177
let hir = cx.tcx.hir();
@@ -177,7 +183,7 @@ impl Item {
177183
def_id,
178184
kind: box kind,
179185
name,
180-
source: source.clean(cx),
186+
span: span.clean(cx),
181187
attrs,
182188
visibility: cx.tcx.visibility(def_id).clean(cx),
183189
}

src/librustdoc/html/render/context.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,15 @@ impl<'tcx> Context<'tcx> {
228228
/// may happen, for example, with externally inlined items where the source
229229
/// of their crate documentation isn't known.
230230
pub(super) fn src_href(&self, item: &clean::Item) -> Option<String> {
231-
if item.source.is_dummy() {
231+
if item.span.is_dummy() {
232232
return None;
233233
}
234234
let mut root = self.root_path();
235235
let mut path = String::new();
236-
let cnum = item.source.cnum(self.sess());
236+
let cnum = item.span.cnum(self.sess());
237237

238238
// We can safely ignore synthetic `SourceFile`s.
239-
let file = match item.source.filename(self.sess()) {
239+
let file = match item.span.filename(self.sess()) {
240240
FileName::Real(ref path) => path.local_path().to_path_buf(),
241241
_ => return None,
242242
};
@@ -270,8 +270,8 @@ impl<'tcx> Context<'tcx> {
270270
(&*symbol, &path)
271271
};
272272

273-
let loline = item.source.lo(self.sess()).line;
274-
let hiline = item.source.hi(self.sess()).line;
273+
let loline = item.span.lo(self.sess()).line;
274+
let hiline = item.span.hi(self.sess()).line;
275275
let lines =
276276
if loline == hiline { loline.to_string() } else { format!("{}-{}", loline, hiline) };
277277
Some(format!(

src/librustdoc/html/render/print_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ fn item_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Mac
937937
Some("macro"),
938938
None,
939939
None,
940-
it.source.span().edition(),
940+
it.span.span().edition(),
941941
);
942942
});
943943
document(w, cx, it, None)

src/librustdoc/html/sources.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ impl DocFolder for SourceCollector<'_, '_> {
4141
// then we need to render it out to the filesystem.
4242
if self.scx.include_sources
4343
// skip all synthetic "files"
44-
&& item.source.filename(self.sess()).is_real()
44+
&& item.span.filename(self.sess()).is_real()
4545
// skip non-local files
46-
&& item.source.cnum(self.sess()) == LOCAL_CRATE
46+
&& item.span.cnum(self.sess()) == LOCAL_CRATE
4747
{
48-
let filename = item.source.filename(self.sess());
48+
let filename = item.span.filename(self.sess());
4949
// If it turns out that we couldn't read this file, then we probably
5050
// can't read any of the files (generating html output from json or
5151
// something like that), so just don't include sources for the

src/librustdoc/json/conversions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::collections::HashSet;
2424
impl JsonRenderer<'_> {
2525
pub(super) fn convert_item(&self, item: clean::Item) -> Option<Item> {
2626
let deprecation = item.deprecation(self.tcx);
27-
let clean::Item { source, name, attrs, kind, visibility, def_id } = item;
27+
let clean::Item { span, name, attrs, kind, visibility, def_id } = item;
2828
let inner = match *kind {
2929
clean::StrippedItem(_) => return None,
3030
x => from_clean_item_kind(x, self.tcx, &name),
@@ -33,7 +33,7 @@ impl JsonRenderer<'_> {
3333
id: from_def_id(def_id),
3434
crate_id: def_id.krate.as_u32(),
3535
name: name.map(|sym| sym.to_string()),
36-
source: self.convert_span(source),
36+
source: self.convert_span(span),
3737
visibility: self.convert_visibility(visibility),
3838
docs: attrs.collapsed_doc_value(),
3939
links: attrs

src/librustdoc/passes/calculate_doc_coverage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl<'a, 'b> fold::DocFolder for CoverageCalculator<'a, 'b> {
212212
return Some(i);
213213
}
214214
clean::ImplItem(ref impl_) => {
215-
let filename = i.source.filename(self.ctx.sess());
215+
let filename = i.span.filename(self.ctx.sess());
216216
if let Some(ref tr) = impl_.trait_ {
217217
debug!(
218218
"impl {:#} for {:#} in {}",
@@ -243,7 +243,7 @@ impl<'a, 'b> fold::DocFolder for CoverageCalculator<'a, 'b> {
243243
None,
244244
);
245245

246-
let filename = i.source.filename(self.ctx.sess());
246+
let filename = i.span.filename(self.ctx.sess());
247247
let has_doc_example = tests.found_tests != 0;
248248
let hir_id = self.ctx.tcx.hir().local_def_id_to_hir_id(i.def_id.expect_local());
249249
let (level, source) = self.ctx.tcx.lint_level_at_node(MISSING_DOCS, hir_id);

src/librustdoc/passes/check_code_block_syntax.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
8686
// We couldn't calculate the span of the markdown block that had the error, so our
8787
// diagnostics are going to be a bit lacking.
8888
let mut diag = self.cx.sess().struct_span_warn(
89-
super::span_of_attrs(&item.attrs).unwrap_or(item.source.span()),
89+
super::span_of_attrs(&item.attrs).unwrap_or(item.span.span()),
9090
"doc comment contains an invalid Rust code block",
9191
);
9292

@@ -110,7 +110,7 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
110110
impl<'a, 'tcx> DocFolder for SyntaxChecker<'a, 'tcx> {
111111
fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
112112
if let Some(dox) = &item.attrs.collapsed_doc_value() {
113-
let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span());
113+
let sp = span_of_attrs(&item.attrs).unwrap_or(item.span.span());
114114
let extra = crate::html::markdown::ExtraInfo::new_did(self.cx.tcx, item.def_id, sp);
115115
for code_block in markdown::rust_code_blocks(&dox, &extra) {
116116
self.check_rust_syntax(&item, &dox, code_block);

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,9 +1226,7 @@ impl LinkCollector<'_, '_> {
12261226
&ori_link.range,
12271227
&item.attrs,
12281228
)
1229-
.unwrap_or_else(|| {
1230-
span_of_attrs(&item.attrs).unwrap_or(item.source.span())
1231-
});
1229+
.unwrap_or_else(|| span_of_attrs(&item.attrs).unwrap_or(item.span.span()));
12321230

12331231
rustc_session::parse::feature_err(
12341232
&self.cx.tcx.sess.parse_sess,
@@ -1693,7 +1691,7 @@ fn report_diagnostic(
16931691
};
16941692

16951693
let attrs = &item.attrs;
1696-
let sp = span_of_attrs(attrs).unwrap_or(item.source.span());
1694+
let sp = span_of_attrs(attrs).unwrap_or(item.span.span());
16971695

16981696
tcx.struct_span_lint_hir(lint, hir_id, sp, |lint| {
16991697
let mut diag = lint.build(msg);

src/librustdoc/passes/doc_test_lints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) {
9797
if tests.found_tests == 0 && cx.tcx.sess.is_nightly_build() {
9898
if should_have_doc_example(cx, &item) {
9999
debug!("reporting error for {:?} (hir_id={:?})", item, hir_id);
100-
let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span());
100+
let sp = span_of_attrs(&item.attrs).unwrap_or(item.span.span());
101101
cx.tcx.struct_span_lint_hir(
102102
crate::lint::MISSING_DOC_CODE_EXAMPLES,
103103
hir_id,
@@ -109,7 +109,7 @@ crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) {
109109
cx.tcx.struct_span_lint_hir(
110110
crate::lint::PRIVATE_DOC_TESTS,
111111
hir_id,
112-
span_of_attrs(&item.attrs).unwrap_or(item.source.span()),
112+
span_of_attrs(&item.attrs).unwrap_or(item.span.span()),
113113
|lint| lint.build("documentation test in private item").emit(),
114114
);
115115
}

src/librustdoc/passes/html_tags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl<'a, 'tcx> DocFolder for InvalidHtmlTagsLinter<'a, 'tcx> {
181181
let sp = match super::source_span_for_markdown_range(tcx, &dox, range, &item.attrs)
182182
{
183183
Some(sp) => sp,
184-
None => span_of_attrs(&item.attrs).unwrap_or(item.source.span()),
184+
None => span_of_attrs(&item.attrs).unwrap_or(item.span.span()),
185185
};
186186
tcx.struct_span_lint_hir(crate::lint::INVALID_HTML_TAGS, hir_id, sp, |lint| {
187187
lint.build(msg).emit()

src/librustdoc/passes/non_autolinks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'a, 'tcx> DocFolder for NonAutolinksLinter<'a, 'tcx> {
7272
let report_diag = |cx: &DocContext<'_>, msg: &str, url: &str, range: Range<usize>| {
7373
let sp = super::source_span_for_markdown_range(cx.tcx, &dox, &range, &item.attrs)
7474
.or_else(|| span_of_attrs(&item.attrs))
75-
.unwrap_or(item.source.span());
75+
.unwrap_or(item.span.span());
7676
cx.tcx.struct_span_lint_hir(crate::lint::NON_AUTOLINKS, hir_id, sp, |lint| {
7777
lint.build(msg)
7878
.span_suggestion(

0 commit comments

Comments
 (0)