Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The inner span for an empty module should point to the module's file #26755

Closed
nrc opened this issue Jul 3, 2015 · 0 comments
Closed

The inner span for an empty module should point to the module's file #26755

nrc opened this issue Jul 3, 2015 · 0 comments
Labels
A-parser Area: The parsing of Rust source code to an AST

Comments

@nrc
Copy link
Member

nrc commented Jul 3, 2015

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.

@nrc nrc added the A-parser Area: The parsing of Rust source code to an AST label Jul 3, 2015
nrc referenced this issue in cassiersg/rustfmt Jul 3, 2015
@nrc nrc closed this as completed in f47d20a Jul 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST
Projects
None yet
Development

No branches or pull requests

1 participant