|
|
|
|
|
by fluffything
2468 days ago
|
|
I don't think typeholes is necessary for that feature. It suffices to just use type check up to the function signature. If I write: fn foo() { 42 }
in Rust, I get an error that says that `i32` (the type of `42`) is not of type `()` (unit), which is the return type of `foo`. So I can just change it to: fn foo() -> i32 { 42 }
instead. The same applies for generics, if I write: fn bar<T>(x: T, y: T) -> T { x + y }
I get the precise error that T does not implement the `Add<T>` trait. In this case the error is precise because there is only a trait in scope that supports `+`, but once there are many traits that would fit, which is rare, the compiler suggests some (often all of them). With that error I can just change that to: fn bar<T: Add>(x: T, y: T) -> T { x + y }
This is all done through local type inference within the function. |
|