Trying to compile the following,
fn do_it() -> Result<i32, u32> { Result::<i32, u32>::Ok(3) } fn main() { println!("{}", do_it()); }
leads to:
./result_test.rs:2:14: 2:17 error: type parameters are not allowed on this type [E0109] ./result_test.rs:2 Result::<i32, u32>::Ok(3) ^~~
Why are type parameters not allowed for this type?
This is a minimal example, my real example is a macro trying to return the following:
match $reader.$read_func() { Ok(n) => Result::<$read_type, LocalReadError>::Ok(n), Err(err) => Result::<$read_type, LocalReadError>::Err( LocalReadError::from(err) ), }
$read_func is a function, $read_type is the return type of this function. (If I had a programmatic way to get this, I would do it, I don't know how, so this is an argument ...); as-is, I get the above error. If I remove the general parameter specification, enter inteference so that it cannot determine the type. (Because it ends with Result<_, LocalReadError> in one match branch and Result<$read_type, _> in another? I'm not sure. He says:
error: unable to infer enough type information about `_`; type annotations or generic parameter binding required [E0282] match $reader.$read_func() { ^~~~~~~~~~~~
)
Note. The question of why type parameters are not allowed is given below. It turns out that this is not the reason that "it is not possible to determine sufficient type information." ( read_func is a function, in my case I pass a template function, but I forget the arg template, which cannot be displayed.)
macros generics type-inference rust
Thanatos
source share