-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Resolve errors for unknown binding should consider commented out code #105469
Comments
@rustbot claim I'll have a go at this but I need some mentoring instructions. This seems to requires parsing comments? |
@estebank I've been thinking about this and I think that perhaps the best way to do this would be as follows:
Obviously we immediately back off silently if bad syntax is encountered (think |
@Ezrashaw I think that a best effort of keeping an AST node (or a spanned list of comments per file) for comments and a simple string search might be enough for this, as any commented out code is bound to be syntactically suspect (and whatever be add has to be cheap both in execution and maintenance burden). |
Right, so all I'm suggesting in addition to that is that we use AST nodes (for easy scoping etc) and that instead of a finicky string search, we just try to parse a let statement (which can be expanded later). AFAIK, parsing is a very small part of the compilers runtime and just parsing a few comments would have a small effect even on that. Edit: the maintenance burden of this would be small, we can just reuse existing machinery. |
My concern is more around the state of the code than anything else: the commented out code might not be parseable by any reasonable parser. But we could tokenize the comments to aid us, and have simplified parsing for things like |
@estebank Hmm, why not just use the normal parsing? I don't really see the reason not to. If the simplified parsing fails, then we ignore silently. Why not with proper parsing too, keep in mind that it's parsing, we aren't doing type checking or anything. |
My concern is that you could have something like
That would require you to try multiple alternative parses of the comments, including some that only work within other items, like the arg parse. That being said, if only a handful of cases are handled I'd still be happy. |
@estebank Yeah, I think for now that your example probably won't be handled, although we could just do completely normal parsing. My main issue is how to decide whether a comment is code or junk (ideally in the lexer), so that we don't have to even parse it. |
When refactoring code, it is not uncommon to comment out pieces of code try try alternatives. When doing so, it's easy to forget to uncomment at least one of the alternatives. Given code like
the compiler should emit output similar to
The text was updated successfully, but these errors were encountered: