Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upbeta and nightly regression: type inference in closure #41727
Comments
thiolliere
changed the title
regression: type inference in closure
beta and nighlty regression: type inference in closure
May 3, 2017
thiolliere
changed the title
beta and nighlty regression: type inference in closure
beta and nightly regression: type inference in closure
May 3, 2017
nagisa
added
the
regression-from-stable-to-beta
label
May 3, 2017
This comment has been minimized.
This comment has been minimized.
|
Quite likely to be XID – we allow ourselves to break code that relies of inference, because otherwise it would be impossible to add new trait implementations. Still tagging as regression so the the cause could be confirmed. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@TimNN inference “breaking” due to new implementation(s) of trait(s). EDIT: of course I typoed it, it is XIB. |
TimNN
added
the
T-compiler
label
May 4, 2017
This comment has been minimized.
This comment has been minimized.
|
XIB = "expected impl breakage" |
nikomatsakis
self-assigned this
May 4, 2017
This comment has been minimized.
This comment has been minimized.
|
triage: P-high We have to figure out the real cause here. Will investigate. |
rust-highfive
added
the
P-high
label
May 4, 2017
This comment has been minimized.
This comment has been minimized.
|
Based on a quick inspection of the code, I would guess that this is fallout from my PR #40570. |
This comment has been minimized.
This comment has been minimized.
|
Minimal reproduction: fn main() {
let mut collision = None;
collision = collision.map_or(Some(22_u32), |c| Some(c.saturating_add(1)));
}Not yet sure which PR is at fault, but #40570 still seems like a likely candidate. Note that the inference here is extremely fragile; removing the @thiolliere -- btw, you probably figured this out, but a workaround for now would be to label the type of |
This comment has been minimized.
This comment has been minimized.
|
OK, so, I think the problem is specifically due to me fixing #18653 (as part of #40570). I believe what's happening is that, when we call It may be that the problem is that, in |
This comment has been minimized.
This comment has been minimized.
|
OK, I did a build before #40570, and my hypothesis is correct: |
This comment has been minimized.
This comment has been minimized.
|
I think we had that discussion on the PR - "this function is already a total hack, but I'm afraid this makes behavior depend on the mood of the union-find algorithm: if a set of (possibly-preexisting) type variables is equated and returned, we'll return one of them "at random"" |
nikomatsakis
referenced this issue
May 9, 2017
Closed
Rust 1.18 regression, constrained-0.1.0, cannot infer type #41796
This comment has been minimized.
This comment has been minimized.
|
TL;DR -- I'm inclined to call this a "not fix". It is a result of fixing #18653, which was a bug where inference would not give itself the required "degrees of freedom" in some cases to find a correct solution. As a result of this, we were able to (correctly, in this case, but not in general) propagate type information from the return value to the expected input types more aggressively in the older compiler than we do now. It is plausible that we could reproduce the "subtyping" or coercion relationship between the type of the output and the first argument -- and of course we will enforce it eventually, the question is how early we do so (i.e., do we enforce it before we type-checking the closure). But this is a non-trivial problem, I think. When figuring out the "expected input types for output type", we'd have to figure out what portion of the general trait obligations to propagate forward, and it's not obvious that these are limited to subtypes. I'm not very comfortable with doing that without more refactorings making it clear what the longer term plan is. |
This comment has been minimized.
This comment has been minimized.
|
Per the previous comment, I'm going to close this issue as "working as expected". @thiolliere, I apologize for the regression and appreciate the bug report. (I see you've already patched your master branch, otherwise I'd open a PR with the fix.) |
thiolliere commentedMay 3, 2017
on nightly and beta my code doesn't compile because the type of a value is unknown:
But it compiles on stable.
stable: rustc 1.17.0 (56124ba 2017-04-24)
beta: rustc 1.18.0-beta.1 (4dce672 2017-04-25)
nightly: rustc 1.19.0-nightly (6a5fc9e 2017-05-02)