make generalization code create new variables in correct universe
In our type inference system, when we "generalize" a type T to become
a suitable value for a type variable V, we sometimes wind up creating
new inference variables. So, for example, if we are making V be some
subtype of `&'X u32`, then we might instantiate V with `&'Y u32`.
This generalized type is then related `&'Y u32 <: &'X u32`, resulting
in a region constriant `'Y: 'X`. Previously, however, we were making
these fresh variables like `'Y` in the "current universe", but they
should be created in the universe of V. Moreover, we sometimes cheat
in an invariant context and avoid creating fresh variables if we know
the result must be equal -- we can only do that when the universes
work out.
2019-02-01 15:41:08 +00:00
|
|
|
// Regression test for an ICE that occurred with the universes code:
|
|
|
|
//
|
|
|
|
// The signature of the closure `|_|` was being inferred to
|
|
|
|
// `exists<'r> fn(&'r u8)`. This should result in a type error since
|
|
|
|
// the signature `for<'r> fn(&'r u8)` is required. However, due to a
|
|
|
|
// bug in the type variable generalization code, the placeholder for
|
|
|
|
// `'r` was leaking out into the writeback phase, causing an ICE.
|
|
|
|
|
|
|
|
trait ClonableFn<T> {
|
|
|
|
fn clone(&self) -> Box<dyn Fn(T)>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T, F: 'static> ClonableFn<T> for F
|
2021-02-09 22:59:32 +00:00
|
|
|
where
|
|
|
|
F: Fn(T) + Clone,
|
|
|
|
{
|
make generalization code create new variables in correct universe
In our type inference system, when we "generalize" a type T to become
a suitable value for a type variable V, we sometimes wind up creating
new inference variables. So, for example, if we are making V be some
subtype of `&'X u32`, then we might instantiate V with `&'Y u32`.
This generalized type is then related `&'Y u32 <: &'X u32`, resulting
in a region constriant `'Y: 'X`. Previously, however, we were making
these fresh variables like `'Y` in the "current universe", but they
should be created in the universe of V. Moreover, we sometimes cheat
in an invariant context and avoid creating fresh variables if we know
the result must be equal -- we can only do that when the universes
work out.
2019-02-01 15:41:08 +00:00
|
|
|
fn clone(&self) -> Box<dyn Fn(T)> {
|
|
|
|
Box::new(self.clone())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Foo(Box<dyn for<'a> ClonableFn<&'a bool>>);
|
|
|
|
|
|
|
|
fn main() {
|
2021-02-09 22:59:32 +00:00
|
|
|
Foo(Box::new(|_| ())); //~ ERROR implementation of `FnOnce` is not general enough
|
make generalization code create new variables in correct universe
In our type inference system, when we "generalize" a type T to become
a suitable value for a type variable V, we sometimes wind up creating
new inference variables. So, for example, if we are making V be some
subtype of `&'X u32`, then we might instantiate V with `&'Y u32`.
This generalized type is then related `&'Y u32 <: &'X u32`, resulting
in a region constriant `'Y: 'X`. Previously, however, we were making
these fresh variables like `'Y` in the "current universe", but they
should be created in the universe of V. Moreover, we sometimes cheat
in an invariant context and avoid creating fresh variables if we know
the result must be equal -- we can only do that when the universes
work out.
2019-02-01 15:41:08 +00:00
|
|
|
}
|