Skip to content

Commit 5a374dc

Browse files
committed
Add some tests to show what happens when you compare two opaque types that are both within the defining scope
1 parent cbfd736 commit 5a374dc

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
// check-pass
4+
5+
type A = impl Foo;
6+
type B = impl Foo;
7+
8+
trait Foo {}
9+
10+
fn muh(x: A) -> B {
11+
if false {
12+
return Bar; // B's hidden type is Bar
13+
}
14+
x // A's hidden type is `Bar`, because all the hidden types of `B` are compared with each other
15+
}
16+
17+
struct Bar;
18+
impl Foo for Bar {}
19+
20+
fn main() {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
type A = impl Foo;
4+
//~^ ERROR could not find defining uses
5+
type B = impl Foo;
6+
7+
trait Foo {}
8+
9+
fn muh(x: A) -> B {
10+
x // B's hidden type is A (opaquely)
11+
}
12+
13+
struct Bar;
14+
impl Foo for Bar {}
15+
16+
fn main() {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: could not find defining uses
2+
--> $DIR/two_tait_defining_each_other2.rs:3:10
3+
|
4+
LL | type A = impl Foo;
5+
| ^^^^^^^^
6+
7+
error: aborting due to previous error
8+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
// check-pass
4+
5+
type A = impl Foo;
6+
type B = impl Foo;
7+
8+
trait Foo {}
9+
10+
fn muh(x: A) -> B {
11+
if false {
12+
return x; // B's hidden type is A (opaquely)
13+
}
14+
Bar // A's hidden type is `Bar`, because all the return types are compared with each other
15+
}
16+
17+
struct Bar;
18+
impl Foo for Bar {}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)