From 813b484d1e8185b746ab67b067fe3ca331b9b07d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Mon, 3 Dec 2018 19:45:06 +0100 Subject: [PATCH] Fix printing of spans with no TyCtxt --- src/librustc/ty/context.rs | 8 ++++++-- src/libsyntax_pos/lib.rs | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index f0411924131..bd8b3e678d8 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1942,8 +1942,12 @@ pub mod tls { /// This is a callback from libsyntax as it cannot access the implicit state /// in librustc otherwise fn span_debug(span: syntax_pos::Span, f: &mut fmt::Formatter<'_>) -> fmt::Result { - with(|tcx| { - write!(f, "{}", tcx.sess.source_map().span_to_string(span)) + with_opt(|tcx| { + if let Some(tcx) = tcx { + write!(f, "{}", tcx.sess.source_map().span_to_string(span)) + } else { + syntax_pos::default_span_debug(span, f) + } }) } diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 4d42b85ea75..4e3d1e89a72 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -611,7 +611,7 @@ impl serialize::UseSpecializedDecodable for Span { } } -fn default_span_debug(span: Span, f: &mut fmt::Formatter) -> fmt::Result { +pub fn default_span_debug(span: Span, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Span") .field("lo", &span.lo()) .field("hi", &span.hi())