-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rust: Type inference for for
loops and array expressions
#19754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@hvitved do you think this is heading in the right direction? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start!
|
||
// for loops with containers | ||
|
||
let vals3 = vec![1, 2, 3]; // $ MISSING: type=vals3:Vec<i32> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not how to make expected type annotations for constructed types, instead you should use the format type=<element>:<path>.<type>
(see
else value = element + ":" + path.toString() + "." + t.toString() |
type=vals3:T.i32
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one still needs to be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated - I'm not 100% confident I've got it right but it's certainly less wrong!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one still needs to be updated.
Co-authored-by: Simon Friis Vindum <[email protected]>
Concerns addressed, PR is approved, and he is away today so not able to add his own approval.
🎉 |
Adds type inference for
for
loops and array expressions. Currently forfor
loops this is limited to loops iterating through arrays.@hvitved please advise.
Iterator
type and perhaps understandIntoIterator
.