]> git.lizzy.rs Git - rust.git/commit
Make `SourceMap` available for early debug-printing of `Span`s
authorAaron Hill <aa1ronham@gmail.com>
Tue, 26 May 2020 17:21:58 +0000 (13:21 -0400)
committerAaron Hill <aa1ronham@gmail.com>
Sun, 31 May 2020 21:30:55 +0000 (17:30 -0400)
commit717fd665ad1095b12907ed0f2426d8eb06c2bddc
tree1b0ff7c2958b6022035bbacf5820ef3688e60270
parent8c5402efdda733d163895d1edb9bcf7f401dd33b
Make `SourceMap` available for early debug-printing of `Span`s

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`
- only if this is not available do we fall back to the raw field output.

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.
src/librustc_interface/interface.rs
src/librustc_span/lib.rs