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

examples: Add stricter impl trait bounds #1518

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

felinira
Copy link
Contributor

Separates out the examples as those don't introduce breaking changes.

See #1515

pub trait CatImpl: PetImpl {}
pub trait CatImpl: PetImpl
where
<Self as ObjectSubclass>::Type: IsA<Pet>,
Copy link
Member

Choose a reason for hiding this comment

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

This one is not inferred by requiring PetImpl, and PetImpl requiring IsA<Pet>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is required, not inferred. Therefore it is showing an error if not specified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

error[E0277]: the trait bound `<Self as glib::subclass::types::ObjectSubclass>::Type: glib::object::IsA<pet::Pet>` is not satisfied
   --> examples/virtual_methods/cat.rs:99:20
    |
99  | pub trait CatImpl: PetImpl
    |                    ^^^^^^^ the trait `glib::object::IsA<pet::Pet>` is not implemented for `<Self as glib::subclass::types::ObjectSubclass>::Type`
    |
note: required by a bound in `pet::PetImpl`
   --> examples/virtual_methods/pet.rs:130:37
    |
128 | pub trait PetImpl: ObjectImpl
    |           ------- required by a bound in this trait
129 | where
130 |     <Self as ObjectSubclass>::Type: IsA<Pet>,
    |                                     ^^^^^^^^ required by this bound in `PetImpl`
help: consider further restricting the associated type
    |
101 |     <Self as ObjectSubclass>::Type: IsA<Cat>, <Self as glib::subclass::types::ObjectSubclass>::Type: glib::object::IsA<pet::Pet>
    |                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error[E0277]: the trait bound `<Obj as glib::subclass::types::ObjectSubclass>::Type: glib::object::IsA<pet::Pet>` is not satisfied
   --> examples/virtual_methods/cat.rs:106:28
    |
106 | unsafe impl<Obj: CatImpl + PetImpl> IsSubclassable<Obj> for Cat where
    |                            ^^^^^^^ the trait `glib::object::IsA<pet::Pet>` is not implemented for `<Obj as glib::subclass::types::ObjectSubclass>::Type`
    |
note: required by a bound in `pet::PetImpl`
   --> examples/virtual_methods/pet.rs:130:37
    |
128 | pub trait PetImpl: ObjectImpl
    |           ------- required by a bound in this trait
129 | where
130 |     <Self as ObjectSubclass>::Type: IsA<Pet>,
    |                                     ^^^^^^^^ required by this bound in `PetImpl`
help: consider further restricting the associated type
    |
107 |     <Obj as ObjectSubclass>::Type: IsA<Cat>, <Obj as glib::subclass::types::ObjectSubclass>::Type: glib::object::IsA<pet::Pet>
    |                                            +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

For more information about this error, try `rustc --explain E0277`.
error: could not compile `gtk-rs-examples` (bin "virtual_methods") due to 2 previous errors

@@ -169,10 +175,13 @@ pub trait PetImplExt: PetImpl {
}

/// The `PetImplExt` trait is implemented for all subclasses that have [`Pet`] in the class hierarchy
impl<T: PetImpl> PetImplExt for T {}
impl<T: PetImpl> PetImplExt for T where <Self as ObjectSubclass>::Type: IsA<Pet> {}
Copy link
Member

Choose a reason for hiding this comment

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

Not necessary (because nothing else can implement this trait) unless the compiler forces you :) It should also be implied via T: PetImpl already

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unless the compiler forces you

It does.

error[E0277]: the trait bound `<Self as glib::subclass::types::ObjectSubclass>::Type: glib::object::IsA<pet::Pet>` is not satisfied
   --> examples/virtual_methods/pet.rs:154:23
    |
154 | pub trait PetImplExt: PetImpl {
    |                       ^^^^^^^ the trait `glib::object::IsA<pet::Pet>` is not implemented for `<Self as glib::subclass::types::ObjectSubclass>::Type`
    |
note: required by a bound in `pet::PetImpl`
   --> examples/virtual_methods/pet.rs:130:37
    |
128 | pub trait PetImpl: ObjectImpl
    |           ------- required by a bound in this trait
129 | where
130 |     <Self as ObjectSubclass>::Type: IsA<Pet>,
    |                                     ^^^^^^^^ required by this bound in `PetImpl`
help: consider further restricting the associated type
    |
154 | pub trait PetImplExt: PetImpl where <Self as glib::subclass::types::ObjectSubclass>::Type: glib::object::IsA<pet::Pet> {
    |                               ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

error[E0277]: the trait bound `<T as glib::subclass::types::ObjectSubclass>::Type: glib::object::IsA<pet::Pet>` is not satisfied
   --> examples/virtual_methods/pet.rs:175:9
    |
175 | impl<T: PetImpl> PetImplExt for T {}
    |         ^^^^^^^ the trait `glib::object::IsA<pet::Pet>` is not implemented for `<T as glib::subclass::types::ObjectSubclass>::Type`
    |
note: required by a bound in `pet::PetImpl`
   --> examples/virtual_methods/pet.rs:130:37
    |
128 | pub trait PetImpl: ObjectImpl
    |           ------- required by a bound in this trait
129 | where
130 |     <Self as ObjectSubclass>::Type: IsA<Pet>,
    |                                     ^^^^^^^^ required by this bound in `PetImpl`
help: consider further restricting the associated type
    |
175 | impl<T: PetImpl> PetImplExt for T where <T as glib::subclass::types::ObjectSubclass>::Type: glib::object::IsA<pet::Pet> {}
    |                                   +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

error[E0277]: the trait bound `<Self as glib::subclass::types::ObjectSubclass>::Type: glib::object::IsA<pet::Pet>` is not satisfied
   --> examples/virtual_methods/pet.rs:154:23
    |
154 | pub trait PetImplExt: PetImpl {
    |                       ^^^^^^^ the trait `glib::object::IsA<pet::Pet>` is not implemented for `<Self as glib::subclass::types::ObjectSubclass>::Type`
    |
note: required by a bound in `pet::PetImpl`
   --> examples/virtual_methods/pet.rs:130:37
    |
128 | pub trait PetImpl: ObjectImpl
    |           ------- required by a bound in this trait
129 | where
130 |     <Self as ObjectSubclass>::Type: IsA<Pet>,
    |                                     ^^^^^^^^ required by this bound in `PetImpl`
help: consider further restricting the associated type
    |
156 |     fn parent_pet(&self) -> bool where <Self as glib::subclass::types::ObjectSubclass>::Type: glib::object::IsA<pet::Pet> {
    |                                  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

error[E0277]: the trait bound `<Self as glib::subclass::types::ObjectSubclass>::Type: glib::object::IsA<pet::Pet>` is not satisfied
   --> examples/virtual_methods/pet.rs:154:23
    |
154 | pub trait PetImplExt: PetImpl {
    |                       ^^^^^^^ the trait `glib::object::IsA<pet::Pet>` is not implemented for `<Self as glib::subclass::types::ObjectSubclass>::Type`
    |
note: required by a bound in `pet::PetImpl`
   --> examples/virtual_methods/pet.rs:130:37
    |
128 | pub trait PetImpl: ObjectImpl
    |           ------- required by a bound in this trait
129 | where
130 |     <Self as ObjectSubclass>::Type: IsA<Pet>,
    |                                     ^^^^^^^^ required by this bound in `PetImpl`
help: consider further restricting the associated type
    |
165 |     fn parent_feed(&self) where <Self as glib::subclass::types::ObjectSubclass>::Type: glib::object::IsA<pet::Pet> {
    |                           ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

For more information about this error, try `rustc --explain E0277`.
error: could not compile `gtk-rs-examples` (bin "virtual_methods") due to 4 previous errors

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.

2 participants