Skip to content
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 interface macro to handle qualified IUnknown parent #1732

Merged
merged 1 commit into from
May 4, 2022

Conversation

rylev
Copy link
Contributor

@rylev rylev commented May 4, 2022

Fixes #1687

We have to differentiate between IUnknown and any other parent COM interface. This is because IUnknown::new only have two generic parameters (T: IUknownImpl and OFFSET) while all other interfaces have new function that takes three generic parameters (Identify: IUnknownImpl, Impl the interface impl, and OFFSET).

This change makes our check for IUnknown a bit more sophisticated. However, this is still a syntactic check and if a ident that is semantically equivalent to IUnknown (but syntactically equivalent) is provided (e.g., type MyIUnknown = windows::core::IUnknown or use core::windows::IUnknown as MyIUnknown), this check will not detect that it's IUnknown and the user will get the bad error message again which just says we're providing three generic arguments to new when two are expected.

The way to actually fix this is to not special case IUnknown and treat it like any other parent interface, but that's a bigger change that will require moving other things around.

@rylev rylev requested a review from kennykerr May 4, 2022 14:28
@rylev
Copy link
Contributor Author

rylev commented May 4, 2022

FWIW: I looked into trying to make IUnknown behave just like any other parent interface and it's not quite possible, because we need to be able to prevent constraints on Impl traits from requiring that the implementor also implement IUnknown. Essentially we want COM classes to provide an implementation for all the COM interfaces except for IUnknown which the wrapper object _Impl struct implements for us.

Here's a branch where I attempt to make the change but run into the issue above.

rylev added a commit to rylev/windows-rs that referenced this pull request May 4, 2022
Copy link
Collaborator

@kennykerr kennykerr left a comment

Choose a reason for hiding this comment

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

Yeah, I'm finding generic programming in Rust to be a lot harder than C++. 😄 While somewhat lossy, this solution should suffice for the time being. Thanks!

@kennykerr kennykerr merged commit 05fd2c3 into microsoft:master May 4, 2022
@rylev rylev deleted the fix-qualified-com-parent branch May 4, 2022 15:59
@rylev rylev mentioned this pull request May 5, 2022
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.

Bug: Qualified paths to IUnknown cause unrelated compiler error with #[interface] proc macro
2 participants