]> git.lizzy.rs Git - rust.git/blob - tests/ui/type-inference/issue-30225.rs
Rollup merge of #106717 - klensy:typo, r=lcnr
[rust.git] / tests / ui / type-inference / issue-30225.rs
1 // Regression test for #30225, which was an ICE that would trigger as
2 // a result of a poor interaction between trait result caching and
3 // type inference. Specifically, at that time, unification could cause
4 // unrelated type variables to become instantiated, if subtyping
5 // relationships existed. These relationships are now propagated
6 // through obligations and hence everything works out fine.
7
8 trait Foo<U,V> : Sized {
9     fn foo(self, u: Option<U>, v: Option<V>) {}
10 }
11
12 struct A;
13 struct B;
14
15 impl Foo<A, B> for () {}      // impl A
16 impl Foo<u32, u32> for u32 {} // impl B, creating ambiguity
17
18 fn toxic() {
19     // cache the resolution <() as Foo<$0,$1>> = impl A
20     let u = None;
21     let v = None;
22     Foo::foo((), u, v);
23 }
24
25 fn bomb() {
26     let mut u = None; // type is Option<$0>
27     let mut v = None; // type is Option<$1>
28     let mut x = None; // type is Option<$2>
29
30     Foo::foo(x.unwrap(),u,v); // register <$2 as Foo<$0, $1>>
31     u = v; // mark $0 and $1 in a subtype relationship
32     //~^ ERROR mismatched types
33     x = Some(()); // set $2 = (), allowing impl selection
34                   // to proceed for <() as Foo<$0, $1>> = impl A.
35                   // kaboom, this *used* to trigge an ICE
36 }
37
38 fn main() {}