d2e2ad559e
Handle subtyping in inference through obligations We currently store subtyping relations in the `TypeVariables` structure as a kind of special case. This branch uses normal obligations to propagate subtyping, thus converting our inference variables into normal fallback. It also does a few other things: - Removes the (unstable, outdated) support for custom type inference fallback. - It's not clear how we want this to work, but we know that we don't want it to work the way it currently does. - The existing support was also just getting in my way. - Fixes #30225, which was caused by the trait caching code pretending type variables were normal unification variables, when indeed they were not (but now are). There is one fishy part of these changes: when computing the LUB/GLB of a "bivariant" type parameter, I currently return the `a` value. Bivariant type parameters are only allowed in a very particular situation, where the type parameter is only used as an associated type output, like this: ```rust pub struct Foo<A, B> where A: Fn() -> B { data: A } ``` In principle, if one had `T=Foo<A, &'a u32>` and `U=Foo<A, &'b u32>` and (e.g.) `A: for<'a> Fn() -> &'a u32`, then I think that computing the LUB of `T` and `U` might do the wrong thing. Probably the right behavior is just to create a fresh type variable. However, that particular example would not compile (because the where-clause is illegal; `'a` does not appear in any input type). I was not able to make an example that *would* compile and demonstrate this shortcoming, and handling the LUB/GLB was mildly inconvenient, so I left it as is. I am considering whether to revisit this or what. I have started a crater run to test the impact of these changes. |
||
---|---|---|
.. | ||
control_flow_graph | ||
graph | ||
obligation_forest | ||
snapshot_map | ||
unify | ||
veccell | ||
accumulate_vec.rs | ||
array_vec.rs | ||
base_n.rs | ||
bitslice.rs | ||
bitvec.rs | ||
blake2b.rs | ||
Cargo.toml | ||
flock.rs | ||
fmt_wrap.rs | ||
fnv.rs | ||
fx.rs | ||
indexed_set.rs | ||
indexed_vec.rs | ||
ivar.rs | ||
lib.rs | ||
small_vec.rs | ||
snapshot_vec.rs | ||
stable_hasher.rs | ||
transitive_relation.rs | ||
tuple_slice.rs |