Stream: t-compiler/rust-analyzer

Topic: include! puzzle

matklad (Jun 16 2021 at 19:02, on Zulip):

Hey, a couple of folks (60fps & discord) independently reached out to me about, and that's a fun issue to think about.

In a nutshell, we can't goto definition inside the include! macro. In some sense, this is expected behavior. From a programming model point of view, include! is indistinguishable from a proc macro which creates the tokens out of thin air (imagine proc_include which does std::fs::read(path).unwrap().parse::<TokenStream>().unwrap()).

From a user's perspective though, the IDE clearly should just "see through" this macro. I wonder if anyone has idea about how to special case this best?

bjorn3 (Jun 16 2021 at 19:04, on Zulip):

In rustc the spans of the tokens are from the included file, not the macro invocation itself afaik.

bjorn3 (Jun 16 2021 at 19:05, on Zulip):

Maybe something like parse the included file as if it is a regular module and then take the tokens from this module and place them at the macro invocation site? Does that make sense?

Jonas Schievink [he/him] (Jun 16 2021 at 19:31, on Zulip):

yeah, rustc has an easier time here since it just loads all files into its source map and can then address any part of any file with a Span

Jonas Schievink [he/him] (Jun 16 2021 at 19:33, on Zulip):

I think we might be able to special-case this in the builtin macro logic by adding an extra TokenMap there

Jonas Schievink [he/him] (Jun 16 2021 at 19:33, on Zulip):

we already track included files there

Last update: Jul 29 2021 at 22:30UTC