Stream: t-compiler/help

Topic: Printing contents of a `Span`


Dylan MacKenzie (Jul 03 2019 at 15:20, on Zulip):

Sorry for the trivial question, but how do I get the contents of a Span as a string for debugging purposes?

Dylan MacKenzie (Jul 03 2019 at 15:32, on Zulip):

I only have access to a TyCtxt, not a Session

Dylan MacKenzie (Jul 03 2019 at 16:03, on Zulip):

Ah, I wanted tcx.gcx.sess.source_map().span_to_string(sp)

varkor (Jul 03 2019 at 16:11, on Zulip):

@Dylan MacKenzie: you can access tcx.sess directly, without going via gcx

varkor (Jul 03 2019 at 16:12, on Zulip):

(more often you want tcx.sess.source_map().span_to_snippet(span))

Dylan MacKenzie (Jul 03 2019 at 16:16, on Zulip):

span_to_snippet is indeed what I wanted

Dylan MacKenzie (Jul 03 2019 at 16:18, on Zulip):

And I now see the Deref impl

Dylan MacKenzie (Jul 03 2019 at 16:18, on Zulip):

Thanks @varkor

varkor (Jul 03 2019 at 16:30, on Zulip):

glad I could help :)

Last update: Nov 11 2019 at 22:05UTC