Skip to content

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

Merged
merged 3 commits into from
Sep 13, 2015

Conversation

matklad
Copy link
Member

@matklad matklad commented Sep 7, 2015

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 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.

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.
@rust-highfive
Copy link
Contributor

r? @huonw

(rust_highfive has picked a reviewer for you, use r? to override)

@matklad
Copy link
Member Author

matklad commented Sep 7, 2015

Oups, the error message for erroneos code struct Foo for changed, that's why the build is failing.

} else {
let token_str = self.this_token_to_string();
return Err(self.fatal(&format!("expected `where`, `{}`, `(`, or `;` after struct \
name, found `{}`", "{", token_str)))
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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
@huonw
Copy link
Member

huonw commented Sep 13, 2015

r? @eddyb (transferring reviewership)

@rust-highfive rust-highfive assigned eddyb and unassigned huonw Sep 13, 2015
@eddyb
Copy link
Member

eddyb commented Sep 13, 2015

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 13, 2015

📌 Commit c87a58f has been approved by eddyb

@bors
Copy link
Collaborator

bors commented Sep 13, 2015

⌛ Testing commit c87a58f with merge 9040b06...

bors added a commit that referenced this pull request Sep 13, 2015
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`.
@bors bors merged commit c87a58f into rust-lang:master Sep 13, 2015
@matklad matklad deleted the remove-dead-code branch July 9, 2019 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants