-
Notifications
You must be signed in to change notification settings - Fork 13k
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
new scoping rules for safe dtors may benefit from variance on type params #21198
Comments
It is now a little more questionable whether the variance changes suggested would suffice. At least, I tried a local hack of making However, I still cannot bootstrap in that case. Here is a gist of a semi-reduced case that I made from my attempt to compile https://gist.github.com/pnkfelix/7b9f0dde7acd8b4f84fe (I am going to try to further reduce the test case so that it stands entirely alone; the one in the gist is still pulling in the |
(discussed the previous comment with @nikomatsakis ; he pointed out that our use of |
(followup to the previous comment: We were mistaken, there is no wrapper trait for |
Triage: too in the weeds for me. |
This is also going over my head. The example in the original issue does compile successfully today, but I can't get an old enough nightly to install with rustup to verify if it did back in 2015. Can anyone comment on this to say if it's still relevant? |
So if I understand what I wrote (back two years ago), I think that this ticket was meant to track parts of the code that might be improved if we added variance of types (with respect to particular type parameters). We at this point do have variance. (Which presumably would explain why the example in the description does compile.) So if there was a big list of instances in the code base that could be improved based on the addition of variance, then I would say we should work our way down that list to clean things up. However, there is no such big list. Therefore, I'm just going to close this ticket. (As far as I can tell there are no references to #21198 in the source tree, and even if there were, the discussion already present here should suffice to provide context about what those references mean.) |
Earlier I wrote:
On IRC
|
Spawned off of #21022, #21972.
As discussed on this commit pnkfelix@8ee3c94
there are example programs (both artificial and in the wild) that have to change under the current implementation of the new scoping rules, but might not require such change if we add support for variance of type parameters: rust-lang/rfcs#281
An easy example of this, taken from the discussion on the above commit, is the following:
Under the region inference constraints (regardless of which scoping rules have been adopted),
'_#1
has to outlivep
, while'_#2
cannot outlivey
, and the call toconstraints
is trying to find a'a
compatible with'_#1
and'_#2
.Under the old scoping rules,
p
andy
had the same scope, so the constraint set is satisfiable.Under the new scoping rules, the scope of
y
is strictly less than that ofp
, so the constraint set is no longer satisfiable.The solution adopted in #21022 is to move the binding of
y
up above the binding ofp
.But an alternative solution is this: If RFC Issue 281 rust-lang/rfcs#281 leads to type parameter variance being implemented, then cases like this might be directly expressible (because the lifetime
'_#1
will continue to outlivep
, but the occurrence ofp
in the call toconstraints
would use variance to assign the scope ofy
(a sublifetime of'_#1
) as the new lifetime embedded within the type ofp
.This ticket is to mark cases that we should revisit if/when type parameter variance is implemented.
The text was updated successfully, but these errors were encountered: