-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Imprement tuple inference #520
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
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 good, I just have one nit about the test :)
check_inference( | ||
r#" | ||
fn test() { | ||
let a: (u32, &str) = (1, "a"); |
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.
the type annotation here kind of makes the type inference for (1, "a")
unnecessary, except that we can see that 1
gets inferred to u32
. Can you add another line without a type annotation, maybe even just ("a", a)
or something, to test a bit more explicitly that tuple expressions get the correct type even when not annotated?
[60; 68) '(a, "b")': ((u32, &str), [unknown]) | ||
[61; 62) 'a': (u32, &str) | ||
[64; 67) '"b"': [unknown] | ||
[79; 80) 'c': ([unknown], [unknown]) |
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.
@flodiebold Thanks for your quick review.
I'm not sure inferring result after 10 line is right.
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.
oh, of course, inferring string literals will only work with #485 :) you could instead add some parameters with declared types and use them instead of literals... so for example
fn test(x: &str, y: isize) {
let a: (u32, &str) = (1, "a");
let b = (a, x);
let c = (y, x);
let d = (c, x);
}
should be able to infer everything...
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.
I see, thanks for your advice.
@flodiebold fixed it. |
Great! bors r+ |
520: Imprement tuple inference r=flodiebold a=h-michael related #394 I'm sorry I'm late. I try implementing array inference next. Co-authored-by: Hirokazu Hata <[email protected]>
|
||
// we have not infered these case yet. | ||
let e = (1, "e"); | ||
let f = (e, "d"); |
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.
I write these two lines to make spec clearly.
Build succeeded |
related #394
I'm sorry I'm late.
I try implementing array inference next.