You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Assume you have mod foo where foo.rs is an empty file. There will be an ItemMod for the module and it's inner span will be a dummy span. It would be more useful if that span could be a zero-length span pointing into foo.rs's FileMap. (This is possible with a PR which should land soon). This would be useful since it gives tools an easy to deal with empty modules, at the moment they have to do all kinds of hacks to handle them.
I experimented a bit with this, but I couldn't get it to work. Here is what I found:
The parser for the outer file will create a new parser to parse foo.rs, that will wrap a TTReader which has a single Eof token. The TTReader is created by running a StringReader over foo.rs (a StringReader being pretty much Rust's lexer). I believe, although I haven't confirmed, that for an empty file, that Eof token comes from syntax::ext::tt::transcribe::tt_next_token (line 217 today). However, there we don't have the FileMap.
My attempt to fix this was to check the result in syntax::parse::filemap_to_parser, if the token of the parser is Eof and the span is DUMMY_SP, then I replaced the span with the zero_length span at the end_pos of the FileMap. This broke sub-module lookup in the parser (which surprised me), the parser's span field was incorrect (one module too far out). At this stage I decided to give up.
The text was updated successfully, but these errors were encountered:
Assume you have
mod foo
where foo.rs is an empty file. There will be anItemMod
for the module and it'sinner
span will be a dummy span. It would be more useful if that span could be a zero-length span pointing into foo.rs'sFileMap
. (This is possible with a PR which should land soon). This would be useful since it gives tools an easy to deal with empty modules, at the moment they have to do all kinds of hacks to handle them.I experimented a bit with this, but I couldn't get it to work. Here is what I found:
The parser for the outer file will create a new parser to parse foo.rs, that will wrap a TTReader which has a single
Eof
token. The TTReader is created by running a StringReader over foo.rs (a StringReader being pretty much Rust's lexer). I believe, although I haven't confirmed, that for an empty file, that Eof token comes fromsyntax::ext::tt::transcribe::tt_next_token
(line 217 today). However, there we don't have theFileMap
.My attempt to fix this was to check the result in
syntax::parse::filemap_to_parser
, if the token of the parser isEof
and the span isDUMMY_SP
, then I replaced the span with the zero_length span at theend_pos
of theFileMap
. This broke sub-module lookup in the parser (which surprised me), the parser'sspan
field was incorrect (one module too far out). At this stage I decided to give up.The text was updated successfully, but these errors were encountered: