Skip to content

Commit 3e7b0b2

Browse files
committed
Make SpanId formatting transparent.
1 parent 5cb1a18 commit 3e7b0b2

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/librustc_interface/callbacks.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ use std::fmt;
1515

1616
/// This is a callback from librustc_ast as it cannot access the implicit state
1717
/// in librustc_middle otherwise.
18-
fn span_debug(span: rustc_span::Span, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18+
fn span_debug(span: rustc_span::SpanId, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1919
tls::with_opt(|tcx| {
2020
if let Some(tcx) = tcx {
21+
let span = tcx.reify_span(span);
2122
write!(f, "{}", tcx.sess.source_map().span_to_string(span))
2223
} else {
2324
rustc_span::default_span_debug(span, f)

src/librustc_span/lib.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl Ord for Span {
239239
}
240240
}
241241

242-
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable)]
242+
#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable)]
243243
#[derive(HashStable_Generic)]
244244
pub enum SpanId {
245245
Span(Span),
@@ -685,23 +685,33 @@ impl rustc_serialize::UseSpecializedDecodable for Span {
685685
}
686686
}
687687

688-
pub fn default_span_debug(span: Span, f: &mut fmt::Formatter<'_>) -> fmt::Result {
689-
f.debug_struct("Span")
690-
.field("lo", &span.lo())
691-
.field("hi", &span.hi())
692-
.field("ctxt", &span.ctxt())
693-
.finish()
688+
pub fn default_span_debug(span: SpanId, f: &mut fmt::Formatter<'_>) -> fmt::Result {
689+
match span {
690+
SpanId::Span(span) => f
691+
.debug_struct("Span")
692+
.field("lo", &span.lo())
693+
.field("hi", &span.hi())
694+
.field("ctxt", &span.ctxt())
695+
.finish(),
696+
SpanId::DefId(did) => f.debug_tuple("DefId").field(&did).finish(),
697+
}
694698
}
695699

696700
impl fmt::Debug for Span {
697701
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
698-
(*SPAN_DEBUG)(*self, f)
702+
(*SPAN_DEBUG)(SpanId::Span(*self), f)
699703
}
700704
}
701705

702706
impl fmt::Debug for SpanData {
703707
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
704-
(*SPAN_DEBUG)(Span::new(self.lo, self.hi, self.ctxt), f)
708+
(*SPAN_DEBUG)(SpanId::Span(Span::new(self.lo, self.hi, self.ctxt)), f)
709+
}
710+
}
711+
712+
impl fmt::Debug for SpanId {
713+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
714+
(*SPAN_DEBUG)(*self, f)
705715
}
706716
}
707717

@@ -1637,7 +1647,7 @@ pub struct FileLines {
16371647
pub lines: Vec<LineInfo>,
16381648
}
16391649

1640-
pub static SPAN_DEBUG: AtomicRef<fn(Span, &mut fmt::Formatter<'_>) -> fmt::Result> =
1650+
pub static SPAN_DEBUG: AtomicRef<fn(SpanId, &mut fmt::Formatter<'_>) -> fmt::Result> =
16411651
AtomicRef::new(&(default_span_debug as fn(_, &mut fmt::Formatter<'_>) -> _));
16421652

16431653
// _____________________________________________________________________________

0 commit comments

Comments
 (0)