Skip to content

Canonicalize types before looking for their definitions. #2084

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 2 commits into from
Jul 31, 2021

Conversation

pcwalton
Copy link
Contributor

In some esoteric cases involving nested templates,
ty.declaration().definition() isn't enough to find the definition: we need
ty.canonical_type().declaration().definition() instead.

Closes #2078.

r? @emilio

@highfive
Copy link

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

It's really weird that we need the canonical type, there and that clang doesn't figure out the definition, but this looks good to me.

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the test failure on tests/headers/layout_cmdline_token.h / tests/expectations/tests/layout_cmdline_token.rs one of the expected outputs needs to be regenerated.

+/// Stores a pointer to the ops struct, and the offset: the place to
+/// write the parsed result in the destination structure.
 pub type cmdline_parse_token_hdr_t = cmdline_token_hdr;

...

thread 'header_layout_cmdline_token_h' panicked at 'Header and binding differ! Run with BINDGEN_OVERWRITE_EXPECTED=1 in the environment to automatically overwrite the expectation or with BINDGEN_TESTS_DIFFTOOL=meld to do this manually.'

pcwalton added 2 commits July 30, 2021 19:44
In some esoteric cases involving nested templates,
`ty.declaration().definition()` isn't enough to find the definition: we need
`ty.canonical_type().declaration().definition()` instead.

Closes rust-lang#2078.
complete type.

It might not if we had to avoid recursion when processing types. Detect that
case and bail out. This bug was being masked by the fact that we didn't always
find definitions for the recursion check and so it didn't trigger, but now that
this check is more reliable we have to be careful in more places.

The test case was reduced from the GCC STL allocator definition.
@pcwalton pcwalton force-pushed the canonicalize-types branch from c6cc0aa to 6a7dff0 Compare July 31, 2021 02:54
@emilio emilio merged commit d1d2eb6 into rust-lang:master Jul 31, 2021
@pcwalton pcwalton deleted the canonicalize-types branch August 2, 2021 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic with double insertion of type when combining CRTP with static assert, nested templates, and inner classes
4 participants