-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Changes from 10 commits
840ef5c
f76b562
51343a5
b89d6d3
62e3cc5
6194676
69da4e7
66d6770
4292b03
dec0deb
639f85a
1622d08
f670fcb
7170e97
d55e8b7
26e7b2d
7a25596
bfaabab
34cd976
d02a728
8c848ac
4530e85
530ded1
21bea7e
96dcdf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| multiplePathResolutions | ||
| | main.rs:1851:25:1851:36 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1851:25:1851:36 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1851:25:1851:36 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1851:25:1851:36 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1851:25:1851:36 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1851:25:1851:36 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1851:46:1851:57 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1851:46:1851:57 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1851:46:1851:57 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1851:46:1851:57 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1851:46:1851:57 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1851:46:1851:57 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1851:67:1851:78 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1851:67:1851:78 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1851:67:1851:78 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1851:67:1851:78 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1851:67:1851:78 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1851:67:1851:78 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1854:26:1854:37 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1854:26:1854:37 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1854:26:1854:37 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1854:26:1854:37 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1854:26:1854:37 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1854:26:1854:37 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1854:47:1854:58 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1854:47:1854:58 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1854:47:1854:58 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1854:47:1854:58 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1854:47:1854:58 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1854:47:1854:58 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1854:68:1854:79 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1854:68:1854:79 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1854:68:1854:79 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1854:68:1854:79 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1854:68:1854:79 | ...::from | file://:0:0:0:0 | fn from | | ||
| | main.rs:1854:68:1854:79 | ...::from | file://:0:0:0:0 | fn from | |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -1810,6 +1810,104 @@ mod indexers { | |||
| } | ||||
| } | ||||
|
|
||||
| mod loops { | ||||
| struct MyCallable { | ||||
| } | ||||
geoffw0 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
|
|
||||
| impl MyCallable { | ||||
| fn new() -> Self { | ||||
| MyCallable {} | ||||
| } | ||||
|
|
||||
| fn call(&self) -> i64 { | ||||
| 1 | ||||
| } | ||||
| } | ||||
|
|
||||
| pub fn f() { | ||||
| // for loops with arrays | ||||
|
|
||||
| for i in [1, 2, 3] { } // $ type=i:i32 | ||||
| for i in [1, 2, 3].map(|x| x + 1) { } // $ MISSING: type=i:i32 | ||||
| for i in [1, 2, 3].into_iter() { } // $ MISSING: type=i:i32 | ||||
|
|
||||
| let vals1 = [1u8, 2, 3]; // $ MISSING: type=vals1:[u8; 3] | ||||
| for u in vals1 { } // $ type=u:u8 | ||||
|
|
||||
| let vals2 = [1u16; 3]; // $ MISSING: type=vals2:[u16; 3] | ||||
| for u in vals2 { } // $ type=u:u16 | ||||
|
|
||||
| let vals3: [u32; 3] = [1, 2, 3]; // $ MISSING: type=vals3:[u32; 3] | ||||
| for u in vals3 { } // $ type=u:u32 | ||||
|
|
||||
| let vals4: [u64; 3] = [1; 3]; // $ MISSING: type=vals4:[u64; 3] | ||||
| for u in vals4 { } // $ type=u:u64 | ||||
|
|
||||
| let mut strings1 = ["foo", "bar", "baz"]; // $ MISSING: type=strings1:[&str; 3] | ||||
| for s in &strings1 { } // $ MISSING: type=s:&str | ||||
| for s in &mut strings1 { } // $ MISSING: type=s:&str | ||||
| for s in strings1 { } // $ type=s:str | ||||
|
|
||||
| let strings2 = [String::from("foo"), String::from("bar"), String::from("baz")]; // $ MISSING: type=strings2:[String; 3] | ||||
| for s in strings2 { } // $ type=s:String | ||||
|
|
||||
| let strings3 = &[String::from("foo"), String::from("bar"), String::from("baz")]; // $ MISSING: type=strings3:&[String; 3] | ||||
| for s in strings3 { } // $ MISSING: type=s:String | ||||
|
|
||||
| let callables = [MyCallable::new(), MyCallable::new(), MyCallable::new()]; // $ MISSING: type=callables:[MyCallable; 3] | ||||
| for c in callables { // $ type=c:MyCallable | ||||
| let result = c.call(); // $ type=result:i64 method=call | ||||
| } | ||||
|
|
||||
| // for loops with ranges | ||||
|
|
||||
| for i in 0..10 { } // $ MISSING: type=i:i32 | ||||
| for u in [0u8 .. 10] { } // $ MISSING: type=u:u8 | ||||
|
|
||||
| let range1 = std::ops::Range { start: 0u16, end: 10u16 }; // $ MISSING: type=range:std::ops::Range<u16> | ||||
| for u in range1 { } // $ MISSING: type=i:u16 | ||||
|
|
||||
| // for loops with containers | ||||
|
|
||||
| let vals3 = vec![1, 2, 3]; // $ MISSING: type=vals3:Vec<i32> | ||||
|
||||
| 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.
Uh oh!
There was an error while loading. Please reload this page.