-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Internally change regions to be covariant #103676
Copy link
Copy link
Open
Labels
A-varianceArea: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)Area: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)C-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.Call for participation: Hard difficulty. Experience needed to fix: A lot.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-varianceArea: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)Area: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)C-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.Call for participation: Hard difficulty. Experience needed to fix: A lot.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
THIS ISSUE IS ONLY ABOUT AN IMPLEMENTATION DETAIL OF RUSTC, IT DOES NOT AFFECT THE RUST LANGUAGE.
Right now regions in rustc are considered to be contravariant wherever they are used:
rust/compiler/rustc_middle/src/ty/relate.rs
Lines 447 to 454 in cdd7afe
rust/compiler/rustc_middle/src/ty/relate.rs
Lines 492 to 497 in cdd7afe
This is confusing and different from outlives, as
'a subtype 'bcurrently means'b outlives 'a. Whenever we switch between "outlives" and "subtyping" for regions, we have to swap the order, e.g.rust/compiler/rustc_infer/src/infer/outlives/env.rs
Lines 137 to 148 in cdd7afe
We've previously discussed this in https://rust-lang.zulipchat.com/#narrow/stream/144729-t-types/topic/relating.20regions.20variance where we ended up agreeing that the variance should be changed to covariance for regions.
Doing so is non-trivial as my first attempt at this ended up missing at least one place resulting in hard to diagnose errors in core. I still want to see this fixed and would be up to review or mentor any work here. This requires some familiarity with the compiler (some knowledge about borrowck and/or the lexical regionck would be helpful) to correctly update relevant comments when doing this change.
edit: we also have to update the
crate_variancesquery for this to work. probably that was the issue I encountered