Skip to content

Commit 9684557

Browse files
committed
Small cleanups
- Use a tuple struct instead of a single field - Enforce calling `source_callsite()` by making the inner span private - Rename `empty` to `dummy`
1 parent 0e574fb commit 9684557

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

Diff for: src/librustdoc/clean/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
118118
};
119119

120120
Some(Item {
121-
source: Span::empty(),
121+
source: Span::dummy(),
122122
name: None,
123123
attrs: Default::default(),
124124
visibility: Inherited,

Diff for: src/librustdoc/clean/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ fn build_module(cx: &DocContext<'_>, did: DefId, visited: &mut FxHashSet<DefId>)
479479
items.push(clean::Item {
480480
name: None,
481481
attrs: clean::Attributes::default(),
482-
source: clean::Span::empty(),
482+
source: clean::Span::dummy(),
483483
def_id: DefId::local(CRATE_DEF_INDEX),
484484
visibility: clean::Public,
485485
stability: None,

Diff for: src/librustdoc/clean/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1882,10 +1882,7 @@ impl Clean<VariantKind> for hir::VariantData<'_> {
18821882

18831883
impl Clean<Span> for rustc_span::Span {
18841884
fn clean(&self, _cx: &DocContext<'_>) -> Span {
1885-
// Get the macro invocation instead of the definition,
1886-
// in case the span is result of a macro expansion.
1887-
// (See rust-lang/rust#39726)
1888-
Span { original: self.source_callsite() }
1885+
Span::from_rustc_span(*self)
18891886
}
18901887
}
18911888

Diff for: src/librustdoc/clean/types.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -1610,31 +1610,36 @@ crate enum VariantKind {
16101610
Struct(VariantStruct),
16111611
}
16121612

1613-
/// Small wrapper around `rustc_span::Span` that adds helper methods.
1613+
/// Small wrapper around `rustc_span::Span` that adds helper methods and enforces calling `source_callsite`.
16141614
#[derive(Clone, Debug)]
1615-
crate struct Span {
1616-
crate original: rustc_span::Span,
1617-
}
1615+
crate struct Span(rustc_span::Span);
16181616

16191617
impl Span {
1620-
crate fn empty() -> Self {
1621-
Self { original: rustc_span::DUMMY_SP }
1618+
crate fn from_rustc_span(sp: rustc_span::Span) -> Self {
1619+
// Get the macro invocation instead of the definition,
1620+
// in case the span is result of a macro expansion.
1621+
// (See rust-lang/rust#39726)
1622+
Self(sp.source_callsite())
1623+
}
1624+
1625+
crate fn dummy() -> Self {
1626+
Self(rustc_span::DUMMY_SP)
16221627
}
16231628

16241629
crate fn span(&self) -> rustc_span::Span {
1625-
self.original
1630+
self.0
16261631
}
16271632

16281633
crate fn filename(&self, sess: &Session) -> FileName {
1629-
sess.source_map().span_to_filename(self.original)
1634+
sess.source_map().span_to_filename(self.0)
16301635
}
16311636

16321637
crate fn lo(&self, sess: &Session) -> Loc {
1633-
sess.source_map().lookup_char_pos(self.original.lo())
1638+
sess.source_map().lookup_char_pos(self.0.lo())
16341639
}
16351640

16361641
crate fn hi(&self, sess: &Session) -> Loc {
1637-
sess.source_map().lookup_char_pos(self.original.hi())
1642+
sess.source_map().lookup_char_pos(self.0.hi())
16381643
}
16391644

16401645
crate fn cnum(&self, sess: &Session) -> CrateNum {

0 commit comments

Comments
 (0)