Rust: Type inference for for loops and array expressions#19754
Rust: Type inference for for loops and array expressions#19754geoffw0 merged 25 commits intogithub:mainfrom
for loops and array expressions#19754Conversation
|
@hvitved do you think this is heading in the right direction? |
|
|
||
| // for loops with containers | ||
|
|
||
| let vals3 = vec![1, 2, 3]; // $ MISSING: type=vals3:Vec<i32> |
There was a problem hiding this comment.
This is not how to make expected type annotations for constructed types, instead you should use the format type=<element>:<path>.<type> (see
type=vals3:T.i32.
There was a problem hiding this comment.
Ah, I think I was relying on the test runner to start suggesting correct syntax, which it doesn't really do for optional results. I've updated the expectations now as best I can - there may still be add mistakes.
There was a problem hiding this comment.
This one still needs to be updated.
There was a problem hiding this comment.
Fair point. 😆
Updated.
|
Ready for review: there are gaps (and apparently a conflict with main), but we get some useful results and I'd like to push towards merging this ASAP. |
paldepind
left a comment
There was a problem hiding this comment.
Looks really great 👍. I've left a few minor comments.
| map1.insert(1, Box::new("one")); // $ method=insert | ||
| map1.insert(2, Box::new("two")); // $ method=insert | ||
| for key in map1.keys() { } // $ method=keys MISSING: type=key:i32 | ||
| for value in map1.values() { } // $ method=values MISSING: type=value:Box type=value:Box.T:&T.str |
There was a problem hiding this comment.
This type annotation has two :s. I think the later should be a . or tweaked in some other way.
There was a problem hiding this comment.
Updated - I'm not 100% confident I've got it right but it's certainly less wrong!
hvitved
left a comment
There was a problem hiding this comment.
One small last thing, otherwise LGTM.
|
|
||
| // for loops with containers | ||
|
|
||
| let vals3 = vec![1, 2, 3]; // $ MISSING: type=vals3:Vec<i32> |
There was a problem hiding this comment.
This one still needs to be updated.
Co-authored-by: Simon Friis Vindum <paldepind@github.com>
Concerns addressed, PR is approved, and he is away today so not able to add his own approval.
|
🎉 |
Adds type inference for
forloops and array expressions. Currently forforloops this is limited to loops iterating through arrays.@hvitved please advise.
Iteratortype and perhaps understandIntoIterator.