dtolnay / dtolnay/reflect

Manually specify type info

Open
#27 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
780
Forks
23
PR merge metrics
No merged PRs in 30d

Description

There are cases where type inference is impossible, even when fully qualified paths to every method/function is given. In those cases the macro author need to specify the type.
Consider this function:
```Rust
fn cmp_str() -> bool {
let __v0 = ::std::str::FromStr::from_str("str");
let __v1 = ::std::result::Result::unwrap(__v0);
let __v2 = ::std::string::ToString::to_string("str");
let __v3 = ::std::cmp::PartialEq::eq(&__v2, &__v1);
__v3
}
```
In this case it can't infer the type of __v0, since it can't know what the Self type of FromStr is. This instance could be fixed if we allowed specifying the Self type. We could then change the first line to:
```Rust
let __v0 = <::std::string::String as ::std::str::FromStr>::from_str("str");
```
A separate issue can arise if we invoke a trait function with generic parameters, and one of the parameters needs to be specified.

I'm not sure what would be a good interface to deal with this issue. We might generate ```INVOKE_WITH_SELF```. where the first parameter is a Type or RuntimeType parameter, and the rest works like regular ```INVOKE```. We might alternatively have a ```set_self``` function that deals with this, that can be used after a normal ```INVOKE```. Unfortunately, this only deals with the Self issue, and not generics in general.

Any suggestions here would be helpful.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.