Skip to content

Commit 813b484

Browse files
committed
Fix printing of spans with no TyCtxt
1 parent 93294ea commit 813b484

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/librustc/ty/context.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1942,8 +1942,12 @@ pub mod tls {
19421942
/// This is a callback from libsyntax as it cannot access the implicit state
19431943
/// in librustc otherwise
19441944
fn span_debug(span: syntax_pos::Span, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1945-
with(|tcx| {
1946-
write!(f, "{}", tcx.sess.source_map().span_to_string(span))
1945+
with_opt(|tcx| {
1946+
if let Some(tcx) = tcx {
1947+
write!(f, "{}", tcx.sess.source_map().span_to_string(span))
1948+
} else {
1949+
syntax_pos::default_span_debug(span, f)
1950+
}
19471951
})
19481952
}
19491953

src/libsyntax_pos/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ impl serialize::UseSpecializedDecodable for Span {
611611
}
612612
}
613613

614-
fn default_span_debug(span: Span, f: &mut fmt::Formatter) -> fmt::Result {
614+
pub fn default_span_debug(span: Span, f: &mut fmt::Formatter) -> fmt::Result {
615615
f.debug_struct("Span")
616616
.field("lo", &span.lo())
617617
.field("hi", &span.hi())

0 commit comments

Comments
 (0)