-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
trigger unsized coercions keyed on Sized bounds #56219
Conversation
116ecff
to
33db7c0
Compare
src/librustc_typeck/check/mod.rs
Outdated
} | ||
} | ||
|
||
/// FIXME: impl Trait why u give me lifetime errors? |
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.
What did you try? You might've had to use + Captures<'tcx>
etc.
LGTM, r? @nikomatsakis |
We should test that with a crater run? |
I first tried to have the function return
I then tried to use the
Of course, my original design had closures instead of a struct implementing It would be nice if you could pinpoint a particular shortcoming with |
You need to write something like this (see #34511 (comment) for more details): impl Iterator<Item=ty::PolyTraitRef<'tcx>> + Captures<'gcx> + 'b In general, add |
This comment has been minimized.
This comment has been minimized.
So does this require a lang-team FCP? |
@arielb1 I think if not FCP we should at least discuss it (and so I've nominated it) since this has user observable type system changes. |
We had a discussion in the @rust-lang/lang meeting and concluded that we should go ahead with this change, at least in some form. Although we are now taking more things into consideration for coercions (namely, pending coercions) and that's a bit risky, it's nice to fix a real problem, and this doesn't seem like a "fundamental complexity change" in the coercion rules. They've always taken into account "information gained from type-checking thus far" and now we are just expanding that to the "complete set of information" (i.e. not just equality constraints, but arbitrary obligations). I'd still personally like to spend some time tomorrow to think over some examples and try to be careful about precisely which obligations we consider, but the lang team is 👍 on the general direction thus far. =) |
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.
OK, I read over the changes, which look good.
My only real hesitation is whether we want to try to be "intensional" about the set of obligations we consider for this role -- i.e., to trace the set of obligations that arise from the surrounding context in the same way we trace the 'expected type'. I believe that the existing closure checking code, which also uses obligations, was sort of aiming for this sort of limitation by tying itself to the case where (a) you have an expected type of an inference variable and (b) you have obligations directly referencing that variable. Pretty hacky, though.
I want to experiment a bit with this branch -- which for example checks for unifications of the expected type inference variable -- to see which things work and which things don't, and if there's much real change. I'm building a local copy for this purpose.
src/librustc_typeck/check/closure.rs
Outdated
proj_predicate | ||
) | ||
}) | ||
Some(()).filter(|()| { |
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.
What is the purpose of this construct? I suspect there's a clearer one out there =)
Note that the obligations here are on the "found type" (i.e., the result of Consider cases like fn let_expansion() -> Box<Error> {
let x = Box::new(!);
x /* should this work? */
} My personal expectation is that this code will work (BTW, it does not work ATM because of subtyping (the "is sized" relationship doesn't propagate through that) - should I change that?), with
I added the |
☔ The latest upstream changes (presumably #56578) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping on this-- did you have a chance to experiment? I'd love to see this land, since it unblocks both |
c0e0d82
to
98faeb5
Compare
☔ The latest upstream changes (presumably #56875) made this pull request unmergeable. Please resolve the merge conflicts. |
This PR causes unsized coercions to not be disabled by `$0: Unsize<dyn Object>` coercion obligations when we have an `$0: Sized` obligation somewhere. Note that `X: Unsize<dyn Object>` obligations can't fail *as obligations* if `X: Sized` holds, so this still maintains some version of monotonicity (I think that an unsized coercion can't be converted to no coercion by unifying type variables). Fixes rust-lang#49593 (unblocking never_type).
98faeb5
to
eeb8c8d
Compare
📌 Commit eeb8c8d has been approved by |
@bors r=nikomatsakis |
📌 Commit 5b74438 has been approved by |
trigger unsized coercions keyed on Sized bounds This PR causes unsized coercions to not be disabled by `$0: Unsize<dyn Object>` coercion obligations when we have an `$0: Sized` obligation somewhere. This should be mostly backwards-compatible, because in these cases not doing the unsize coercion should have caused the `$0: Sized` obligation to fail. Note that `X: Unsize<dyn Object>` obligations can't fail *as obligations* if `X: Sized` holds, so this still maintains some version of monotonicity (I think that an unsized coercion can't be converted to no coercion by unifying type variables). Fixes #49593 (unblocking never_type). r? @eddyb cc @nikomatsakis
💔 Test failed - status-travis |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
⌛ Testing commit 5b74438 with merge cb5e1d32cf5d87c40fa31cf876fd394b12861a1b... |
💔 Test failed - status-travis |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@bors retry |
trigger unsized coercions keyed on Sized bounds This PR causes unsized coercions to not be disabled by `$0: Unsize<dyn Object>` coercion obligations when we have an `$0: Sized` obligation somewhere. This should be mostly backwards-compatible, because in these cases not doing the unsize coercion should have caused the `$0: Sized` obligation to fail. Note that `X: Unsize<dyn Object>` obligations can't fail *as obligations* if `X: Sized` holds, so this still maintains some version of monotonicity (I think that an unsized coercion can't be converted to no coercion by unifying type variables). Fixes #49593 (unblocking never_type). r? @eddyb cc @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
This PR causes unsized coercions to not be disabled by
$0: Unsize<dyn Object>
coercion obligations when we have an$0: Sized
obligation somewhere.This should be mostly backwards-compatible, because in these cases not doing the unsize coercion should have caused the
$0: Sized
obligation to fail.Note that
X: Unsize<dyn Object>
obligations can't fail as obligations ifX: Sized
holds, so this still maintains some version of monotonicity (I think that an unsized coercion can't be converted to no coercion by unifying type variables).Fixes #49593 (unblocking never_type).
r? @eddyb
cc @nikomatsakis