Make SourceMap available for early debug-printing of Spans by Aaron1011 · Pull Request #72618 · rust-lang/rust (original) (raw)

Normally, we debug-print Spans using the SourceMap retrieved from
the global TyCtxt. However, we fall back to printing out the Span's
raw fields (instead of a file and line number) when we try to print a
Span before a TyCtxt is available. This makes debugging early phases
of the compile, such as parsing, much more difficult.

This commit stores a SourceMap in rustc_span::GlOBALS as a fallback.
When a TyCtxt is not available, we try to retrieve one from GLOBALS

I'm not sure how to write a test for this - however, this can be
verified locally by setting RUSTC_LOG="rustc_parse=debug", and
verifying that the output contains filenames and line numbers.