diff options
| author | Joshua Nelson <jyn514@gmail.com> | 2020-12-12 09:38:35 -0500 |
|---|---|---|
| committer | Joshua Nelson <jyn514@gmail.com> | 2020-12-12 09:40:34 -0500 |
| commit | 9684557c8f1b9fd55cb6fcc27533044022b0ed22 (patch) | |
| tree | 6cb36f325697f5969c6cee21f13e8b02e4d7c372 | |
| parent | 0e574fb39ad99a7ffbfd7f2d52603d890dfa2084 (diff) | |
| download | rust-9684557c8f1b9fd55cb6fcc27533044022b0ed22.tar.gz rust-9684557c8f1b9fd55cb6fcc27533044022b0ed22.zip | |
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`
| -rw-r--r-- | src/librustdoc/clean/auto_trait.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/clean/inline.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 5 | ||||
| -rw-r--r-- | src/librustdoc/clean/types.rs | 25 |
4 files changed, 18 insertions, 16 deletions
diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 8feef9c259c..7a61a169c2b 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -118,7 +118,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { }; Some(Item { - source: Span::empty(), + source: Span::dummy(), name: None, attrs: Default::default(), visibility: Inherited, diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index f3067360f06..42778867bf8 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -479,7 +479,7 @@ fn build_module(cx: &DocContext<'_>, did: DefId, visited: &mut FxHashSet<DefId>) items.push(clean::Item { name: None, attrs: clean::Attributes::default(), - source: clean::Span::empty(), + source: clean::Span::dummy(), def_id: DefId::local(CRATE_DEF_INDEX), visibility: clean::Public, stability: None, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index a21e9d9820c..1a63a5092ca 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1882,10 +1882,7 @@ impl Clean<VariantKind> for hir::VariantData<'_> { impl Clean<Span> for rustc_span::Span { fn clean(&self, _cx: &DocContext<'_>) -> Span { - // Get the macro invocation instead of the definition, - // in case the span is result of a macro expansion. - // (See rust-lang/rust#39726) - Span { original: self.source_callsite() } + Span::from_rustc_span(*self) } } diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index a8626af8832..0228d63ac00 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1610,31 +1610,36 @@ crate enum VariantKind { Struct(VariantStruct), } -/// Small wrapper around `rustc_span::Span` that adds helper methods. +/// Small wrapper around `rustc_span::Span` that adds helper methods and enforces calling `source_callsite`. #[derive(Clone, Debug)] -crate struct Span { - crate original: rustc_span::Span, -} +crate struct Span(rustc_span::Span); impl Span { - crate fn empty() -> Self { - Self { original: rustc_span::DUMMY_SP } + crate fn from_rustc_span(sp: rustc_span::Span) -> Self { + // Get the macro invocation instead of the definition, + // in case the span is result of a macro expansion. + // (See rust-lang/rust#39726) + Self(sp.source_callsite()) + } + + crate fn dummy() -> Self { + Self(rustc_span::DUMMY_SP) } crate fn span(&self) -> rustc_span::Span { - self.original + self.0 } crate fn filename(&self, sess: &Session) -> FileName { - sess.source_map().span_to_filename(self.original) + sess.source_map().span_to_filename(self.0) } crate fn lo(&self, sess: &Session) -> Loc { - sess.source_map().lookup_char_pos(self.original.lo()) + sess.source_map().lookup_char_pos(self.0.lo()) } crate fn hi(&self, sess: &Session) -> Loc { - sess.source_map().lookup_char_pos(self.original.hi()) + sess.source_map().lookup_char_pos(self.0.hi()) } crate fn cnum(&self, sess: &Session) -> CrateNum { |
