From 38444f61bb89cd8217477e2864e19966ba72acd4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 22 Apr 2021 15:14:49 +0200 Subject: [PATCH] * Rename Span::from_rustc_span to Span::new * Rename Span::wrap to Span::wrap_raw * Improve documentation for Span::wrap_raw --- src/librustdoc/clean/inline.rs | 2 +- src/librustdoc/clean/mod.rs | 3 ++- src/librustdoc/clean/types.rs | 12 ++++++------ src/librustdoc/html/highlight.rs | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index b3b89e6e673..43979423ae6 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -517,7 +517,7 @@ fn build_module( } } - let span = clean::Span::from_rustc_span(cx.tcx.def_span(did)); + let span = clean::Span::new(cx.tcx.def_span(did)); clean::Module { items, span } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b3fc1e73f78..3d65fcedaf4 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -95,7 +95,8 @@ 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 = Span::from_rustc_span({ + + let span = Span::new({ let where_outer = self.where_outer(cx.tcx); let sm = cx.sess().source_map(); let outer = sm.lookup_char_pos(where_outer.lo()); diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index d79fcdd5fce..fd4748f1f50 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -343,7 +343,7 @@ fn to_remote(url: impl ToString) -> ExternalLocation { rustc_data_structures::static_assert_size!(Item, 56); crate fn rustc_span(def_id: DefId, tcx: TyCtxt<'_>) -> Span { - Span::from_rustc_span(def_id.as_local().map_or_else( + Span::new(def_id.as_local().map_or_else( || tcx.def_span(def_id), |local| { let hir = tcx.hir(); @@ -1947,15 +1947,15 @@ impl Span { /// span will be updated to point to the macro invocation instead of the macro definition. /// /// (See rust-lang/rust#39726) - crate fn from_rustc_span(sp: rustc_span::Span) -> Self { + crate fn new(sp: rustc_span::Span) -> Self { Self(sp.source_callsite()) } - /// Unless you know what you're doing, use [`Self::from_rustc_span`] instead! + /// Unless you know what you're doing, use [`Self::new`] instead! /// - /// Contrary to [`Self::from_rustc_span`], this constructor wraps the span as is and don't - /// perform any operation on it, even if it's from a macro expansion. - crate fn wrap(sp: rustc_span::Span) -> Span { + /// This function doesn't clean the span at all. Compare with [`Self::new`]'s body to see the + /// difference. + crate fn wrap_raw(sp: rustc_span::Span) -> Span { Self(sp) } diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 62f8618b8c6..253343b560d 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -597,7 +597,7 @@ fn string( LinkFromSrc::Local(span) => { eprintln!("==> {:?}:{:?}", span.lo(), span.hi()); context - .href_from_span(clean::Span::wrap(*span)) + .href_from_span(clean::Span::wrap_raw(*span)) .map(|s| format!("{}{}", root_path, s)) } LinkFromSrc::External(def_id) => { -- 2.44.0