Skip to content

Commit e1e0989

Browse files
committed
Add a new test case to verify behavior.
1 parent 6b1c52f commit e1e0989

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// run-pass
2+
#![feature(trait_upcasting)]
3+
#![allow(incomplete_features)]
4+
5+
trait Foo<T: Default + ToString>: Bar<i32> + Bar<T> {}
6+
trait Bar<T: Default + ToString> {
7+
fn bar(&self) -> String {
8+
T::default().to_string()
9+
}
10+
}
11+
12+
struct S1;
13+
14+
impl Bar<i32> for S1 {}
15+
impl Foo<i32> for S1 {}
16+
17+
struct S2;
18+
impl Bar<i32> for S2 {}
19+
impl Bar<bool> for S2 {}
20+
impl Foo<bool> for S2 {}
21+
22+
fn test1(x: &dyn Foo<i32>) {
23+
let s = x as &dyn Bar<i32>;
24+
assert_eq!("0", &s.bar().to_string());
25+
}
26+
27+
fn test2(x: &dyn Foo<bool>) {
28+
let p = x as &dyn Bar<i32>;
29+
assert_eq!("0", &p.bar().to_string());
30+
let q = x as &dyn Bar<bool>;
31+
assert_eq!("false", &q.bar().to_string());
32+
}
33+
34+
fn main() {
35+
let s1 = S1;
36+
test1(&s1);
37+
let s2 = S2;
38+
test2(&s2);
39+
}

0 commit comments

Comments
 (0)