Skip to content

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

Merged
merged 4 commits into from
Jan 13, 2019
Merged

Imprement tuple inference #520

merged 4 commits into from
Jan 13, 2019

Conversation

h-michael
Copy link
Contributor

related #394

I'm sorry I'm late.

I try implementing array inference next.

Copy link
Member

@flodiebold flodiebold left a 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");
Copy link
Member

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])
Copy link
Contributor Author

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.

Copy link
Member

@flodiebold flodiebold Jan 13, 2019

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...

Copy link
Contributor Author

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.

@h-michael
Copy link
Contributor Author

@flodiebold fixed it.

@flodiebold
Copy link
Member

Great!

bors r+

bors bot added a commit that referenced this pull request Jan 13, 2019
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");
Copy link
Contributor Author

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.

@bors
Copy link
Contributor

bors bot commented Jan 13, 2019

Build succeeded

@bors bors bot merged commit 139da08 into rust-lang:master Jan 13, 2019
@h-michael h-michael deleted the tuple branch January 13, 2019 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants