Skip to content

Commit e4b762b

Browse files
committed
add regression test for #30225
Fixes #30225
1 parent e58e2b4 commit e4b762b

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/test/compile-fail/issue-30225.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Regression test for #30225, which was an ICE that would trigger as
12+
// a result of a poor interaction between trait result caching and
13+
// type inference. Specifically, at that time, unification could cause
14+
// unrelated type variables to become instantiated, if subtyping
15+
// relationships existed. These relationships are now propagated
16+
// through obligations and hence everything works out fine.
17+
18+
trait Foo<U,V> : Sized {
19+
fn foo(self, u: Option<U>, v: Option<V>) {}
20+
}
21+
22+
struct A;
23+
struct B;
24+
25+
impl Foo<A, B> for () {} // impl A
26+
impl Foo<u32, u32> for u32 {} // impl B, creating ambiguity
27+
28+
fn toxic() {
29+
// cache the resolution <() as Foo<$0,$1>> = impl A
30+
let u = None;
31+
let v = None;
32+
Foo::foo((), u, v);
33+
}
34+
35+
fn bomb() {
36+
let mut u = None; // type is Option<$0>
37+
let mut v = None; // type is Option<$1>
38+
let mut x = None; // type is Option<$2>
39+
40+
Foo::foo(x.unwrap(),u,v); // register <$2 as Foo<$0, $1>>
41+
u = v; // mark $0 and $1 in a subtype relationship
42+
//~^ ERROR mismatched types
43+
x = Some(()); // set $2 = (), allowing impl selection
44+
// to proceed for <() as Foo<$0, $1>> = impl A.
45+
// kaboom, this *used* to trigge an ICE
46+
}
47+
48+
fn main() {}

0 commit comments

Comments
 (0)