gtk-rs-core icon indicating copy to clipboard operation
gtk-rs-core copied to clipboard

[BUG] The private struct is exposed with `ObjectSubclassIsExt::imp`

Open SeaDve opened this issue 3 years ago • 6 comments

Bug description

Before ObjectSubclassIsExt::imp, the private struct would only be exposed when explicitly allowed to. Now, it can be accessed publicly, even from a different module.

Exposing the private struct may be okay on applications, but not on public API's

SeaDve avatar Jan 17 '22 05:01 SeaDve

Also before the private struct was exported via that trait, see

https://github.com/gtk-rs/gtk-rs-core/blob/7cfcc209b46c54730293a6c0387bbc57524b80bc/glib/src/wrapper.rs#L437-L439

I'm quite sure the compiler was complaining if you didn't mark it as public, and because the from_instance() comes from a public trait you could already do exactly the same before.

sdroege avatar Jan 17 '22 08:01 sdroege

I think it would only be possible before if the private struct is also public?

SeaDve avatar Jan 17 '22 12:01 SeaDve

But it would have to be always public because it was leaked via the associated type. You could have done <YourPublicType as ObjectSubclassIs>::Subclass::from_instance() in the worst case, but I think the compiler even gave you an error because otherwise the private typed was leaked as public API.

sdroege avatar Jan 17 '22 12:01 sdroege

I agree this isn't ideal if it can be avoided (which may be difficult with all the trait magic going on). But the harm seems limited if the private struct has no public members.

ids1024 avatar Jan 18 '22 21:01 ids1024

Note that if you mark all your private struct items as pub(super) you cannot access them from a different file even if you had access to the private struct through the imp method.

bilelmoussaoui avatar Mar 26 '22 09:03 bilelmoussaoui