rust/compiler/rustc_hir_analysis/src
Matthias Krüger a5caa989c9
Rollup merge of #107339 - aliemjay:covariant, r=lcnr
internally change regions to be covariant

Surprisingly, we consider the reference type `&'a T` to be contravaraint in its lifetime parameter. This is confusing and conflicts with the documentation we have in the reference, rustnomicon, and rustc-dev-guide. This also arguably not the correct use of terminology since we can use `&'static u8` in a place where `&' a u8` is expected, this implies that `&'static u8 <: &' a u8` and consequently `'static <: ' a`, hence covariance.

Because of this, when relating two types, we used to switch the argument positions in a confusing way:
`Subtype(&'a u8 <: &'b u8) => Subtype('b <: 'a) => Outlives('a: 'b) => RegionSubRegion('b <= 'a)`

The reason for the current behavior is probably that we wanted `Subtype('b <: 'a)` and `RegionSubRegion('b <= 'a)` to be equivalent, but I don' t think this is a good reason since these relations are sufficiently different in that the first is a relation in the subtyping lattice and is intrinsic to the type-systems, while the the second relation is an implementation detail of regionck.

This PR changes this behavior to use covariance, so..
`Subtype(&'a u8 <: &'b u8) => Subtype('a <: 'b) => Outlives('a: 'b) => RegionSubRegion('b <= 'a) `

Resolves #103676

r? `@lcnr`
2023-01-28 05:20:18 +01:00
..
astconv Rollup merge of #107100 - compiler-errors:issue-107087, r=lcnr 2023-01-28 05:20:16 +01:00
check Compute generator saved locals on MIR. 2023-01-27 20:10:06 +00:00
coherence Introduce GeneratorWitnessMIR. 2023-01-27 18:58:44 +00:00
collect fix up subst_identity vs skip_binder; add some FIXMEs as identified in review 2023-01-26 20:28:31 -07:00
impl_wf_check fix: use LocalDefId instead of HirId in trait res 2023-01-23 11:42:18 +00:00
outlives even more unify Projection/Opaque in outlives code 2023-01-19 15:31:53 +03:00
structured_errors rustc_hir_analysis: remove ref patterns 2023-01-17 07:48:19 +00:00
variance Rollup merge of #107339 - aliemjay:covariant, r=lcnr 2023-01-28 05:20:18 +01:00
autoderef.rs fix: use LocalDefId instead of HirId in trait res 2023-01-23 11:42:18 +00:00
bounds.rs Rework hir Bounds collection 2022-12-28 23:40:09 +00:00
check_unused.rs Remove double spaces after dots in comments 2023-01-17 08:09:33 +00:00
collect.rs Rollup merge of #107100 - compiler-errors:issue-107087, r=lcnr 2023-01-28 05:20:16 +01:00
constrained_generic_params.rs Stop using BREAK & CONTINUE in compiler 2023-01-17 23:17:51 -08:00
errors.rs Move autoderef to rustc_hir_analysis 2023-01-11 20:12:57 +00:00
hir_wf_check.rs fix: use LocalDefId instead of HirId in trait res 2023-01-23 11:42:18 +00:00
impl_wf_check.rs change impl_trait_ref query to return EarlyBinder; remove bound_impl_trait_ref query; add EarlyBinder to impl_trait_ref in metadata 2023-01-14 00:29:56 -07:00
lib.rs change fn_sig query to use EarlyBinder; remove bound_fn_sig query; add EarlyBinder to fn_sig in metadata 2023-01-26 20:28:25 -07:00
structured_errors.rs rustc_typeck to rustc_hir_analysis 2022-09-27 10:37:23 +02:00