Description
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 'b
currently 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_variances
query for this to work. probably that was the issue I encountered