4db6a9b82f
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.
25 lines
735 B
Rust
25 lines
735 B
Rust
// 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
|
|
where F: Fn(T) + Clone {
|
|
fn clone(&self) -> Box<dyn Fn(T)> {
|
|
Box::new(self.clone())
|
|
}
|
|
}
|
|
|
|
struct Foo(Box<dyn for<'a> ClonableFn<&'a bool>>);
|
|
|
|
fn main() {
|
|
Foo(Box::new(|_| ())); //~ ERROR mismatched types
|
|
}
|