Omitting the return type of a trait method to use () doesn't work with associated_type_defaults when the default is () (type R = ();):
https://play.rust-lang.org/?gist=2b56fc463679d93f1c24a8af3495c776&version=nightly&mode=debug&edition=2015
error[E0053]: method `overload` has an incompatible type for trait
--> src/main.rs:36:39
|
30 | fn overload(self) -> Self::R;
| ------- type in trait
...
36 | fn overload(self) /*-> Self::R*/ {
| ^ expected associated type, found ()
|
= note: expected type `fn((i32, bool)) -> <(i32, bool) as overload::Overload>::R`
found type `fn((i32, bool))`
error[E0053]: method `overload` has an incompatible type for trait
--> src/main.rs:53:39
|
30 | fn overload(self) -> Self::R;
| ------- type in trait
...
53 | fn overload(self) /*-> Self::R*/ {
| ^ expected associated type, found ()
|
= note: expected type `fn((i32, bool, f32)) -> <(i32, bool, f32) as overload::Overload>::R`
found type `fn((i32, bool, f32))`
Even when I uncomment both occurrences of /*-> Self::R*/, it doesn't work:
error[E0308]: mismatched types
--> src/main.rs:36:35
|
36 | fn overload(self) -> Self::R {
| ______________________________________^
37 | | let (a, b) = self; // destructure args
38 | | println!("i32 and bool {:?}", (a, b));
39 | | }
| |_________^ expected associated type, found ()
|
= note: expected type `<(i32, bool) as overload::Overload>::R`
found type `()`
error[E0308]: mismatched types
--> src/main.rs:53:35
|
53 | fn overload(self) -> Self::R {
| ______________________________________^
54 | | let (a, b, c) = self; // destructure args
55 | | println!("i32 and bool and f32 {:?}", (a, b, c));
56 | | }
| |_________^ expected associated type, found ()
|
= note: expected type `<(i32, bool, f32) as overload::Overload>::R`
found type `()`
I also have to uncomment both occurrences of // type R = (); to get it to compile.
Which defeats the purpose of using associated_type_defaults here :/
I think this should work as intended though.
And when the default type is not () (e.g. type R = i32;), it should still work to only write fn overload(self) -> Self::R { without overriding type R in this impl (if one wants to use the default R here).
Omitting the return type of a trait method to use
()doesn't work withassociated_type_defaultswhen the default is()(type R = ();):https://play.rust-lang.org/?gist=2b56fc463679d93f1c24a8af3495c776&version=nightly&mode=debug&edition=2015
Even when I uncomment both occurrences of
/*-> Self::R*/, it doesn't work:I also have to uncomment both occurrences of
// type R = ();to get it to compile.Which defeats the purpose of using
associated_type_defaultshere :/I think this should work as intended though.
And when the default type is not
()(e.g.type R = i32;), it should still work to only writefn overload(self) -> Self::R {without overridingtype Rin thisimpl(if one wants to use the defaultRhere).