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

glib: Add unimplemented diagnostic to IsA linking to the wrapper macro #1552

Merged

Conversation

felinira
Copy link
Contributor

@felinira felinira commented Oct 23, 2024

Emits errors such as these:

error[E0277]: the trait `glib::object::IsA<purrable::Purrable>` is not implemented for `tabby_cat::TabbyCat`
  --> examples/virtual_methods/main.rs:38:30
   |
38 |     let purrable = tabby_cat.upcast_ref::<Purrable>();
   |                              ^^^^^^^^^^ requires `tabby_cat::TabbyCat` to be a GObject that can be cast as `purrable::Purrable`
   |
   = help: the trait `glib::object::IsA<purrable::Purrable>` is not implemented for `tabby_cat::TabbyCat`
   = note: if this is your own object, use the `glib::wrapper!` macro to implement this trait: https://gtk-rs.org/gtk-rs-core/stable/latest/docs/glib/macro.wrapper.html
   = help: the following other types implement trait `glib::object::IsA<T>`:
             `tabby_cat::TabbyCat` implements `glib::object::IsA<Object>`
             `tabby_cat::TabbyCat` implements `glib::object::IsA<cat::Cat>`
             `tabby_cat::TabbyCat` implements `glib::object::IsA<tabby_cat::TabbyCat>`
note: required by a bound in `upcast_ref`
  --> /home/fina/Code/gtk-rs-core/glib/src/object.rs:118:5

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
warning: `gtk-rs-examples` (bin "virtual_methods") generated 1 warning
error: could not compile `gtk-rs-examples` (bin "virtual_methods") due to 9 previous errors; 1 warning emitted

Compared to

error[E0277]: the trait bound `tabby_cat::TabbyCat: glib::object::IsA<purrable::Purrable>` is not satisfied
   --> examples/virtual_methods/main.rs:38:30
    |
38  |     let purrable = tabby_cat.upcast_ref::<Purrable>();
    |                              ^^^^^^^^^^ the trait `glib::object::IsA<purrable::Purrable>` is not implemented for `tabby_cat::TabbyCat`
    |
    = help: the following other types implement trait `glib::object::IsA<T>`:
              `tabby_cat::TabbyCat` implements `glib::object::IsA<Object>`
              `tabby_cat::TabbyCat` implements `glib::object::IsA<cat::Cat>`
              `tabby_cat::TabbyCat` implements `glib::object::IsA<tabby_cat::TabbyCat>`
note: required by a bound in `upcast_ref`
   --> /home/fina/Code/gtk-rs-core/glib/src/object.rs:116:15
    |
114 |     fn upcast_ref<T: ObjectType>(&self) -> &T
    |        ---------- required by a bound in this associated function
115 |     where
116 |         Self: IsA<T>,
    |               ^^^^^^ required by this bound in `Cast::upcast_ref`

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
warning: `gtk-rs-examples` (bin "virtual_methods") generated 1 warning
error: could not compile `gtk-rs-examples` (bin "virtual_methods") due to 9 previous errors; 1 warning emitted

The most important part here being the link to the glib::wrapper! docs.

We could probably add a few more diagnostics to some of the core traits, but I am not sure where it makes sense.

@felinira felinira force-pushed the wip/diagnostic-on-unimplemented branch from 5fc120b to ee0ebee Compare October 23, 2024 13:22
@bilelmoussaoui
Copy link
Member

The gir/gir-files changes looks unrelated, otherwise lgtm

sdroege
sdroege previously approved these changes Oct 23, 2024
@felinira
Copy link
Contributor Author

The gir/gir-files changes looks unrelated, otherwise lgtm

Egh, submodules and I will never be good friends. Fixed.

@bilelmoussaoui bilelmoussaoui merged commit ff441ba into gtk-rs:main Oct 23, 2024
48 checks passed
@bilelmoussaoui
Copy link
Member

Thank you!

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.

3 participants