Skip to content

Conversation

@MarijnS95
Copy link
Contributor

All the cleanups from #1153 separated in nicely documented, individually reviewable commits.

This includes a simplification of where T: IsA<Foo> into specifying the trait bound directly when the type parameter is defined: func<T: IsA<Foo>>.

As requested by @GuillaumeGomez the "fix" for clippy::use_self is in here too, but in hindsight I'm not too sure how useful it is. This is what it does:

diff --git a/gdk/src/auto/device.rs b/gdk/src/auto/device.rs
index f53e2a154f..9994f88311 100644
--- a/gdk/src/auto/device.rs
+++ b/gdk/src/auto/device.rs
@@ -450,7 +450,7 @@ impl Device {
     }

     #[doc(alias = "changed")]
-    pub fn connect_changed<F: Fn(&Device) + 'static>(&self, f: F) -> SignalHandlerId {
+    pub fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
         unsafe extern "C" fn changed_trampoline<F: Fn(&Device) + 'static>(
             this: *mut ffi::GdkDevice,
             f: glib::ffi::gpointer,

F of the function and F of the unsafe extern "C" fn still mean the same thing, though they are now textually different. The the nested unsafe extern "C" fn cannot reference type parameters (Self is a type parameter!) of the surrounding context, which is why it still carries Device instead of Self.
A bit further don this code-block the pointer of changed_trampoline::<F> is taken, to pass type parameter F of the surrounding function into the nested one (hence they reference the same type).

@GuillaumeGomez
Copy link
Member

So I guess if we regen with this, the only changes we should see are the Self ones. If so, looks good to me! :)

MarijnS95 added 6 commits May 24, 2021 20:02
This member was always set to `false`, and by extension `fn
get_base_alias` always returns `None`.
Most of the callers were not reading the return value leading to
potentially missed failed type parameter "allocations".  This could have
been solved with `#[must_use]` but the function might as well panic
directly as this situation is extremely unlikely (need more than `11`
type parameters) but nevertheless not valid.  If it occurs in the
future `gir` should be adjusted to have more type parameters available,
ie. by using full names.
This simplifies the code (gir and generated results) a fair bit by
placing the trait bound directly after the type parameter definition,
instead of using a separate `where` block.
Regardless of it being a generic type with the first type parameter or
not.
@GuillaumeGomez GuillaumeGomez merged commit de679ce into gtk-rs:master May 24, 2021
@GuillaumeGomez
Copy link
Member

Thanks!

@MarijnS95 MarijnS95 deleted the bounds-refactor branch May 24, 2021 18:23
gstreamer-github pushed a commit to sdroege/gstreamer-rs that referenced this pull request May 27, 2021
Trait bounds moved from `where T: Foo` directly into the type parameter
definition at `<T: Foo>`: gtk-rs/gir#1160.
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