-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Fix pretty printing an AST representing &(mut ident)
#80205
Fix pretty printing an AST representing &(mut ident)
#80205
Conversation
r? @davidtwco (rust-highfive has picked a reviewer for you, use r? to override) |
I didn't find a place to test the help diagnostics of the parser. Are these actually tested? |
Yes, diagnostics are thoroughly tested. Just add code (the code from the issue you opened) to a file in Note that you will need to add |
I added a minimal test case that should cover the entire issue. All other code in the issue can be reduced to this test case. |
`PatKind::Ref(PatKind::Ident(BindingMode::ByValue(Mutability::Mut), ..), ..)` is an AST representing `&(mut ident)`. It was errorneously printed as `&mut ident` which reparsed into a syntactically different AST. This affected help diagnostics in the parser.
@bors r+ |
📌 Commit b05ab18 has been approved by |
☀️ Test successful - checks-actions |
The PR fixes a misguiding help diagnostic in the parser that I reported in #80186. I discovered that the parsers recovery and reporting logic was correct but the pretty printer produced wrong code for the example. (Details in #80186 (comment))
Example:
The AST fragment
PatKind::Ref(PatKind::Ident(BindingMode::ByValue(Mutability::Mut), ..), Mutability::Not)
was printed to be
&mut ident
. But this wouldn't round trip through parsing again, because then it would be:PatKind::Ref(PatKind::Ident(BindingMode::ByValue(Mutability::Not), ..), Mutability::Mut)
Now the pretty-printer prints
&(mut ident)
. Reparsing that code results in the AST fragmentPatKind::Ref(PatKind::Paren(PatKind::Ident(BindingMode::ByValue(Mutability::Mut), ..)), Mutability::Not)
which I think should behave like the original pattern.
Old diagnostic:
New diagnostic:
Fixes #80186