Skip to content

Commit

Permalink
* Rename Span::from_rustc_span to Span::new
Browse files Browse the repository at this point in the history
* Rename Span::wrap to Span::wrap_raw
* Improve documentation for Span::wrap_raw
  • Loading branch information
GuillaumeGomez committed Aug 5, 2021
1 parent 2a3b71a commit 38444f6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ impl Clean<Item> for doctree::Module<'_> {

// 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());
Expand Down
12 changes: 6 additions & 6 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ crate struct Item {
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();
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ fn string<T: Display>(
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) => {
Expand Down

0 comments on commit 38444f6

Please sign in to comment.