Why does the universal syntax for calling a function compile when there is no call to a regular function?

Here is the code that demonstrates my question:

trait T { type A; fn get(&mut self) -> Self::A; } struct Foo; impl T for Foo { type A = i32; fn get(&mut self) -> i32 { 3 } } struct Wrapped<F, V> { func: F, cached: Option<V>, } impl<F, R> T for Wrapped<F, R::A> where F: FnMut() -> R, R: T, R::A: Copy, { type A = R::A; fn get(&mut self) -> R::A { let v: R::A = self.cached.unwrap_or_else(|| (self.func)().get()); self.cached = Some(v); v } } fn make_foo() -> Foo { Foo } fn main() { let mut wrapped: Wrapped<fn() -> Foo, i32> = Wrapped { func: make_foo as fn() -> Foo, cached: None, }; T::get(&mut wrapped); // the following does not compile: WHY? // wrapped.get(); } 

Rust playground

Shouldn't the syntax for calling a universal function be the same as a regular function call?

This error message is:

 rustc 1.15.1 (021bd294c 2017-02-08) error[E0284]: type annotations required: cannot resolve `<_ as T>::A == _` --> <anon>:44:13 | 44 | wrapped.get(); | 

I know that the problem is that I am using impl T<F, R::A> , i.e. impl for the associated type. There is a workaround avoiding this related type:

 struct Wrapped<R: T, F: FnMut() -> R> { func: F, cached: Option<R::A> } 

but that is not my question. I'm interested in the reason for the difference between UFCS and a regular function call.

+8
rust
source share

No one has answered this question yet.

See related questions:

36
Why try! () And? Do not compile when used in a function that does not return a parameter or result?
nine
Embedding Nested Features
5
The borrowed value is not long enough for a compiler error for struct
5
Explicit type annotation for generic generic type constructor
5
What argument to pass and how to find out its type?
3
Using Trait types with rust-portaudio in non-blocking mode
2
Can I use bound constants to generalize array size arguments to functions?
one
Caught between life and the FFI place
0
Encoding stronger WinApi security through Rust RFI
0
How many structure fields can be generics using the same higher constellation?

All Articles