-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Dowgrade/Upgrade
not ususable in traits
#1322
Comments
Here is a standalone version of the problem for easier testing: trait Downgrade
where
Self: Sized,
{
type Weak: Upgrade;
fn downgrade(&self) -> Self::Weak;
}
trait Upgrade
where
Self: Sized,
{
type Strong;
fn upgrade(&self) -> Option<Self::Strong>;
}
trait Mytrait: Downgrade {
fn mushroom(&self) {
let weak = self.downgrade();
let this = weak.upgrade().unwrap();
this.snake();
}
fn snake(&self) {}
}
fn main() {} |
As for user-level workarounds, you can add a trait Mytrait: Downgrade where Self::Weak: Upgrade<Strong = Self> {
fn mushroom(&self) {
let weak = self.downgrade();
let this: Self = weak.upgrade().unwrap();
this.snake();
}
fn snake(&self) {}
} Ah, no the library-level change won't work (as-is at least), since errors when applying the naive change to `glib`error[E0271]: type mismatch resolving `<<T as Downgrade>::Weak as Upgrade>::Strong == &T`
--> glib/src/clone.rs:57:17
|
56 | impl<T: Downgrade> Downgrade for &T {
| - found this type parameter
57 | type Weak = T::Weak;
| ^^^^^^^ expected `&T`, found type parameter `T`
|
= note: expected reference `&_`
found type parameter `_`
note: required by a bound in `Downgrade::Weak`
--> glib/src/clone.rs:18:24
|
18 | type Weak: Upgrade<Strong = Self>;
| ^^^^^^^^^^^^^ required by this bound in `Downgrade::Weak`
error[E0271]: type mismatch resolving `<<T as Downgrade>::Weak as Upgrade>::Strong == BorrowedObject<'a, T>`
--> glib/src/object.rs:4426:17
|
4423 | impl<'a, T: crate::clone::Downgrade + ObjectType> crate::clone::Downgrade
| - found this type parameter
...
4426 | type Weak = <T as crate::clone::Downgrade>::Weak;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `BorrowedObject<'_, T>`, found type parameter `T`
|
= note: expected struct `BorrowedObject<'a, T>`
found type parameter `T`
note: required by a bound in `Downgrade::Weak`
--> glib/src/clone.rs:18:24
|
18 | type Weak: Upgrade<Strong = Self>;
| ^^^^^^^^^^^^^ required by this bound in `Downgrade::Weak`
error[E0271]: type mismatch resolving `<ObjectImplWeakRef<BoxedAnyObject> as Upgrade>::Strong == BoxedAnyObject`
--> glib/src/boxed_any_object.rs:37:5
|
37 | #[glib::object_subclass]
| ^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<ObjectImplWeakRef<BoxedAnyObject> as Upgrade>::Strong == BoxedAnyObject`
|
note: expected this to be `imp::BoxedAnyObject`
--> glib/src/subclass/object_impl_ref.rs:157:19
|
157 | type Strong = ObjectImplRef<T>;
| ^^^^^^^^^^^^^^^^
= note: expected struct `imp::BoxedAnyObject`
found struct `ObjectImplRef<imp::BoxedAnyObject>`
note: required by a bound in `Downgrade::Weak`
--> glib/src/clone.rs:18:24
|
18 | type Weak: Upgrade<Strong = Self>;
| ^^^^^^^^^^^^^ required by this bound in `Downgrade::Weak`
= note: this error originates in the attribute macro `glib::object_subclass` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0271`.
error: could not compile `glib` (lib) due to 3 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile `glib` (lib) due to 3 previous errors |
fails with:
I tried adding a bound tying back
Upgrade::Strong
with the trait but that doesn't work either:Is there a way to make this work easily?
The text was updated successfully, but these errors were encountered: