-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
permit crate
in absolute paths
#45477
Comments
Interesting. Mind if I give this a try? If yes, where should I start to investigate this? |
I would love it if you did! I started the other day trying to write up mentoring instructions, but I never quite finished. This gist contains what I did so far. Maybe the best way to start is just to read a bit into some of the code mentioned there, to get a feeling for how things work today. You can reach out on gitter with questions, too. I will try to extend the directions, or perhaps @petrochenkov has thoughts -- he knows this part of the code better than I. |
Got it. It seems that @petrochenkov has self-assigned the issue to him. I did message him on gitter to ask whether he needed help. Nevertheless, I will go through the code base, and if there is anything I find interesting while working on this issue I will be sure to extend the directions. |
So @petrochenkov is not working on this issue. Can I get assigned to this issue please? I don't think I have permission to self-assign. |
Sorry for spamming. I think only repo members can assign assignees to the project. So I will just leave a comment that I will be working on this issue :) |
Moreover, only repo members can be assigned to the repo issues on GitHub, so I can't add you to the "Assignees" list either. |
Hi, So what's the best way to test the parser that I wrote for this issue? I understand that there is a file called testparser.py within the project directory. However, how can I invoke the testparser.py to test specifically my changes? Do I need to augment testparser.py? Or do I have to write unit tests on a separate file, call the function that I wrote within the unit tests and test it against custom test cases? |
@power10dan |
Mentoring instructions from @nikomatsakis in #45477 (comment) seem to be much more complex than what's needed to do the job. There are three places that need to be tweaked:
Alternative implementation:
|
@petrochenkov I also feel that the mentor instruction is a bit complex too. My thoughts for implementing this are the following : ( I am working on the use crate :: case)
I think my approach is a bit more complex than it needs to be. But I think I will take @petrochenkov 's advice. What do you guys think? |
@power10dan |
I agree that my instructions are complex =) they were mostly notes to myself, as I hadn't yet settled in my mind how I thought things should be implemented (at which point I would go back and simplify...). However, I was thinking about his over the weekend, and I thought we ought to clarify something: Precisely what are we aiming to accept? Today, one can write Unfortunately, that leads to a parsing conflict between "crate the visibility modifier" and "crate the absolute path" is unfortunate. This must be resolved somehow. I see the following options:
Earlier, I wrote that we ought to do adopt the second approach, and I still think it is the one I would prefer. But it does raise a question: do we also want to accept I think some part of my hesitation in writing up the instructions was trying to decide how to resolve this discrepancy one way or the other. Whatever we wind up doing, I think that ultimately I think we will need some form of decision to clarify our intentions here. |
@nikomatsakis I'm pretty sure disambiguating
|
Wait, so I am a bit confused. Should we adopt the case where we allow ::crate::a ::b and disallow crate::a ::b until future release? Because if that's the case, then I shall modify my parser to look for :: followed by crate instead of the one I was aiming to implement, which is crate followed by ::. Also for disambiguating for cases such as struct S(crate:: a:: b), my thoughts for implementing this part of the feature is that we should gobble up each word in the expression ( I think there is a built-in function for this), turn it into a token (like 'struct', 'S(crate::a ::b)') , and check if the token starts with "struct." If it is, then we know that we are dealing with structs with some expression S(crate:: foo:bazz). Then, we can just keep parsing the expression into tokens, and check if the inner path ( the expression surrounded by the parenthesis) is crate followed by ::. If it is, then we allow it since it's crate. Otherwise, if it is not, then we know that it isn't crate, and we disambiguate it. I am not sure if this is the way to go, but this is my understanding of how to use tokens and parser.rs to parse the expression. I ran into similar problems that @nikomatsakis was talking |
This is also what I am advocating. I agree you make a good case for why
Right, and I guess we can just leave it that way for now. I would like to revisit this topic but -- as we've said earlier -- I'd rather do so after we've gained experience and can have more informed opinions.
This is the plan, but not within a use crate::foo::bar;
fn baz() {
bar(); // equivalent to next line
::crate::foo::bar();
}
The parser already has a notion of tokens and so forth -- it sounded to me from your description like you are "reinventing the wheel" a bit. That said, I've still got a few questions myself about the best way to implement this, let me try to write a second comment asking @petrochenkov their opinion, since they know this code better than I. |
Maybe worth spelling out a bit how you see
with an initial segment consisting of the
Is that correct? At least that is how I interpreted this:
At first, I found that surprising, because we represent the paths (We should also look forward a bit to a world where |
In this alternative version, I guess the major downside is that we don't have enough information -- if I understood -- to pretty-print faithfully, right? In particular, it sounds like you were suggesting that the parser would parse in That said, I guess one could imagine things like |
See #45771, no pretty printing is affected. (Sorry, @power10dan, it was better to just do the implementation than continuing discussion about details speculatively.) |
Seems like the practice is to close these "intermediate" issues and keep the base issue (#44660) open for tracking. |
As part of #44660, we plan to support absolute paths that begin with
crate
. The RFC was actually a bit vague about howcrate::foo
paths work outside ofuse
items. I'm going to go with the interpretation described by @rpjohnst, that one would write::crate::foo
to reference the itemfoo
from outside of ause
statement.This means we want to support
use
statements like this:and "absolute" code references like this:
This version also avoids a parsing ambiguity around tuple structs and the
crate
visibility modifier:The text was updated successfully, but these errors were encountered: