-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Unable to inference a result type of an indexing operation #2534
Comments
These are not related to arrays -- it's indexing expressions which aren't implemented yet. I think there's nothing stopping us from doing that, just no-one has done it yet. So all these indexing expressions get inferred as unknown; in cases foo1, foo2, foo4 and foo5 we then infer the type of baz from the later usage, except in foo5 we get it wrong because we don't handle |
@flodiebold Oh, you are right - looks like I didn't compress the test case enough, the simplest case would be fn main() {
let foo = || {
return 1;
};
} (foo gets resolved to |
Yeah, that's the second thing I wrote -- when handling |
Ok, I've split the issue into two so that there is some place to subscribe to and track progress. |
It seems not fixed yet. |
I think the main remaining issue is performing autoderef for indexing operations. We might also need to apply unsized coercions in the case of arrays, I haven't checked. |
I now checked and we do need to perform unsized coercions. Also, there's an issue with type variable fallback in the common case of So to summarize, to get inference for
How complicated such a simple expression can be 😄 |
Autoref and unsizing are done now. |
The only remaining problem here is handling integer variables so that |
Just tested this and |
See the linked Chalk issue rust-lang/chalk#327. |
I see, thank you for linking the related Chalk issue. |
Even after that Chalk issue was solved, |
We're not making use of the Chalk support yet. |
While browsing Blandy & Orendorff I found more test cases: let a1 = String::new();
let b1 = &a1[1..];
let c1 = &a1[..];
let d1 = &a1[..2];
let e1 = &a1[1..2];
let a2 = "";
let b2 = &a2[1..];
let c2 = &a2[..];
let d2 = &a2[..2];
let e2 = &a2[1..2];
let a3 = [1, 2, 3];
let b3 = &a3[1..];
let c3 = &a3[..];
let d3 = &a3[..2];
let e3 = &a3[1..2]; |
I suppose we should use the new |
@lnicola that's basically it, yeah. I actually started this already but didn't finish yet, IIRC it caused some more necessary changes. (You need a kind per variable in the Canonical, so you need to copy around and specify these variable kinds in lots of places, and so on...) |
This means we need to keep track of the kinds (general/int/float) of variables in `Canonical`, which requires some more ceremony. (It also exposes some places where we're not really dealing with canonicalization correctly -- another thing to be cleaned up when we switch to using Chalk's types directly.) Should fix the last remaining issue of rust-lang#2534.
This means we need to keep track of the kinds (general/int/float) of variables in `Canonical`, which requires some more ceremony. (It also exposes some places where we're not really dealing with canonicalization correctly -- another thing to be cleaned up when we switch to using Chalk's types directly.) Should fix the last remaining issue of rust-lang#2534.
5149: Implement Chalk variable kinds r=flodiebold a=flodiebold This means we need to keep track of the kinds (general/int/float) of variables in `Canonical`, which requires some more ceremony. (It also exposes some places where we're not really dealing with canonicalization correctly -- another thing to be cleaned up when we switch to using Chalk's types directly.) Should fix the last remaining issue of #2534. Co-authored-by: Florian Diebold <[email protected]>
This means we need to keep track of the kinds (general/int/float) of variables in `Canonical`, which requires some more ceremony. (It also exposes some places where we're not really dealing with canonicalization correctly -- another thing to be cleaned up when we switch to using Chalk's types directly.) Should fix the last remaining issue of rust-lang#2534.
5149: Implement Chalk variable kinds r=flodiebold a=flodiebold This means we need to keep track of the kinds (general/int/float) of variables in `Canonical`, which requires some more ceremony. (It also exposes some places where we're not really dealing with canonicalization correctly -- another thing to be cleaned up when we switch to using Chalk's types directly.) Should fix the last remaining issue of #2534. Co-authored-by: Florian Diebold <[email protected]>
Now this is blocked on a working version of rust-lang/chalk#555, and then we'll still need to adapt the logic in RA to search for impls for integer types when the self type is an integer variable (and same for floats). |
Hi everyone, I was under impression that type inference involving arrays should work, but it is behaving weirdly:
The type inferred for
baz
isusize
forfoo1
andfoo2
(good),{unknown}
forfoo3
andfoo4
(I would expect that type inference is not too hard there) and()
forfoo5
(plain wrong!).Tested with the latest master (4444192)
Edit: there are two separate issues: type in foo3 and foo4 is not inferred because it is an indexing operation and is inferred incorrectly in foo5 because of the
return
statement in the closure (#2547 )The text was updated successfully, but these errors were encountered: