-
Notifications
You must be signed in to change notification settings - Fork 926
Removing empty type parameter list results in invalid Rust code #4621
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
Comments
I spent a little bit of time looking into this. The issue can be tracked down to Lines 468 to 501 in 17003ce
|
@ytmimi I'm new to this project and just had a look at this issue. I understand, what's happening, but I'm not so sure about the expected result. I could remove the if-condition, so the match-block is executed whether the args are empty or not. That leads to the result that the line
is not changed (what I thought was the expected result). But that fails the test case of #3639, since it looks to me, that the expectation there is, that the |
@sec65 - i believe there's probably at least a couple callsites of the function Yacin referenced above, so you may want to see if you can drive differentiating behavior in that function by incorporating a new parameter that the calling functions can provide (e.g. don't remove for paths/segments, but do remove for empty associated constraints) and thanks for working on this! |
Thanks for your reply. I had a look into it, but unfortunately the distinction is not that easy (at least for me ;-): The
But it seems to me, that I don't have this information down in the rewrite-methods (?), so I can't distinguish there. And I'm not sure, if it's good to pass this information through all the methods in between. Or is there already any possibility to know where it comes from? And, what excactly is the condition, that it should be removed or not? E.g. for the aboved mentioned term Or maybe, the best solution would be to add paranthesis as proposed by rust, since from my point of view |
It's definitely a problem that needs to be solved. We never want to have rustfmt accept an input that's valid, compilable code and produce an output which isn't. I suspect this probably isn't a terribly common occurrence (certainly not a widespread, every day encounter), and the available workarounds play into priority, but it's still something that needs to be addressed. I've not really had a chance to look at the code but based on what you're saying it sounds like it may not be feasible to easily pass along context through call args.
Perhaps. One of the benefits of the formatting model rustfmt employs is that it's possible and relatively straightforward to make such transformations. Are you thinking for cast expressions to just look at the type and if the type kind is path or whichever variant(s) with empty args to wrap in parens? |
Also I acknowledge the easy route would be to simple change the way we handle empty arg lists, but that's desired behavior in most other contexts and is how rustfmt has behaved forever. I'd be highly hesitant to change that behavior just for this case |
Sorry, I realized this would actually be significantly more complicated as it really has to be considered in the broader context, particularly some right-most path ending the lhs operand in the presence of the Really appreciate you looking at this one @sec65 and you're absolutely free to continue working on it, but I'm going to remove the If you're interested in contributing to the project, I'll note there's a number of other issues with the |
@calebcartwright Thanks for your response and help. In that case I will look for some other issue. |
@sec65 Just wanted to apologize for the misleading I know you're on the lookout for other issues. If you find one you'd like to work on you can comment |
(playground)
gets formatted into
The text was updated successfully, but these errors were encountered: