-
Notifications
You must be signed in to change notification settings - Fork 13.4k
libsyntax: remove dead code from parser.rs #28286
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
Conversation
Both `parse_tuple_struct_body` and `parse_item_struct` handled the case of unit like struct. The redundancy is removed, `parse_tuple_struct_body` now handles only real tuple structs.
r? @huonw (rust_highfive has picked a reviewer for you, use r? to override) |
Oups, the error message for erroneos code |
} else { | ||
let token_str = self.this_token_to_string(); | ||
return Err(self.fatal(&format!("expected `where`, `{}`, `(`, or `;` after struct \ | ||
name, found `{}`", "{", token_str))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be generated automatically, using the parser methods to check for the various tokens?
Also, {
is escaped using {{
in format strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really know for sure, I just moved this piece of code from parse_tuple_struct_body
, here: https://github.com/matklad/rust/blob/3a360fca78b415d31783ec715a2c9024a89eeb75/src/libsyntax/parse/parser.rs#L4806-L4807 :)
If I just remove this explicit check and if test, then everything works, but the error message for one tests changes and the build fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say I can fix { escaping in this PR, in two places (there is a second similar error message in parse_record_struct_body
).
As for the removing the explicit error check, I'm not so sure:
- this PR does not change behavior at all, it just rearranges/removes code. Changes to code and tests are better done in a separate PR, if needed.
- this error message looks better then the autogenerated one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I didn't realize it was pre-existing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So should I fix the { issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would be good to clear that up.
Escape `{` in format strings as `{{`, instead of using a substitution
r? @eddyb (transferring reviewership) |
@bors r+ |
📌 Commit c87a58f has been approved by |
There is a dead code in libsyntax/parser/parse.rs, when parsing structs. Two functions are involved: * [parse_item_struct](https://github.com/rust-lang/rust/blob/cd9c9f048f6aa0be091cd9835771ba0712bead4e/src/libsyntax/parse/parser.rs#L4691) * [parse_tuple_struct_body](https://github.com/rust-lang/rust/blob/cd9c9f048f6aa0be091cd9835771ba0712bead4e/src/libsyntax/parse/parser.rs#L4769) The problem is that both functions handle the case with unit structs. But because `parse_tuple_struct_body` is called from `parse_item_struct`, it never faces this case. This PR removes unit struct case from `parse_tuple_struct_body` function. I tested with `make -j8 check-statge1`.
There is a dead code in libsyntax/parser/parse.rs, when parsing structs.
Two functions are involved:
The problem is that both functions handle the case with unit structs. But because
parse_tuple_struct_body
is called fromparse_item_struct
, it never facesthis case.
This PR removes unit struct case from
parse_tuple_struct_body
function. I tested withmake -j8 check-statge1
.