-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Covariance-related GAT lifetime mismatch #89352
Comments
So, surprisingly, changing DetailsSomehow, a Edit: |
Okay, so I've dug into this a little bit. And I thought I would share where I'm at. First, let's look at the root cause of this problem: the One potentially solution I had was to just always prefer the projection candidate. Unfortunately, this ran into a problem with the following case: fn discr<T, U>(v: T, value: U)
where
<T as DiscriminantKind>::Discriminant: PartialEq<U>,
{
assert!(discriminant_value(&v) == value);
} Basically, the param_env gets a One thing I'm exploring right now is to make candidate preference depend on if it's a |
Prefer projection candidates instead of param_env candidates for Sized predicates Fixes rust-lang#89352 Also includes some drive by logging and verbose printing changes that I found useful when debugging this, but I can remove this if needed. This is a little hacky - but imo no more than the rest of `candidate_should_be_dropped_in_favor_of`. Importantly, in a Chalk-like world, both candidates should be completely compatible. r? `@nikomatsakis`
Prefer projection candidates instead of param_env candidates for Sized predicates Fixes rust-lang#89352 Also includes some drive by logging and verbose printing changes that I found useful when debugging this, but I can remove this if needed. This is a little hacky - but imo no more than the rest of `candidate_should_be_dropped_in_favor_of`. Importantly, in a Chalk-like world, both candidates should be completely compatible. r? ``@nikomatsakis``
…rors Revert "Prefer projection candidates instead of param_env candidates for Sized predicates" Fixes rust-lang#93262 Reopens rust-lang#89352 This was a hack that seemed to have no negative side-effects at the time. Given that the latter has a workaround and likely less common than the former, it makes sense to revert this change. r? `@compiler-errors`
Revert "Prefer projection candidates instead of param_env candidates for Sized predicates" Fixes rust-lang#93262 Reopens rust-lang#89352 This was a hack that seemed to have no negative side-effects at the time. Given that the latter has a workaround and likely less common than the former, it makes sense to revert this change. r? `@compiler-errors`
I think this isnt solely a gats issue you can reproduce it on stable playground This technically makes reverting the fix a breaking change since the fix hit stable, if you look at the playground you'll see that it compiles on stable but not on latest nightly |
uh oh |
Okay, so this "only" hit stable on Rust 1.60. So it "only" needs a stable backport if we want to keep this revert for now. I'm going to label for lang team to discuss. Brief summary: #96593 just hit nightly, which is a revert of the above hack. Unfortunately this now changes stable behavior (as opposed to only GATs behavior, which was expected). I'm going to try to schedule a crater run later today to get some data on if this actually effects anyone. To make things more interesting, the code in this example compiles with We have three options:
Between the 3, I would prefer 2. |
@craterbot run name=92191_revert mode=check-only start=master#4c60a0ea5b2385d7400df9db1ad04e96f2a4c154 end=master#bdcb6a99e853732f8ec050ae4986aa3af51d44c5 |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
Yes, that makes sense: the issue there really comes down to the where clause. Crater results look clean though. As discussed on Zulip (https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Covariance-related.20GAT.20lifetime.20mismatch.20.2389352/near/281881315), accepting that for beta backport. |
The nominated portion of this got resolved when #96593 got beta-backported. Technically, the non-GATs reproduction that #96593 broke got "stabilized" in 1.60 - but this falls under accidental stabilization and is reverted in 1.61 (it was too close to release train to stable-backport). Removing I-lang-nominated. |
This now compiles, since NLL stabilization. |
Actually, there was a bug test that got properly moved during stabilization. Closing. |
I tried this code:
I expected to see this happen: Successful compilation.
Instead, this happened: Errors as follows.
Note that it expected and found "type
Sized
", which doesn't make sense. Additionally, I don't see what is restricting's
to outlive'a
; and indeed, the error can be worked around.Meta
Playground:
The original use-case tied the lifetime parameter of the GAT to the type in typical fashion. Discovered in this URLO thread.
@rustbot label +F-generic_associated_types +A-lifetimes +requires-nightly +A-diagnostics
The text was updated successfully, but these errors were encountered: