Add some tests to show what happens when you compare two opaque types that are both within the defining scope
This commit is contained in:
parent
cbfd736292
commit
5a374dc813
4 changed files with 64 additions and 0 deletions
20
src/test/ui/impl-trait/two_tait_defining_each_other.rs
Normal file
20
src/test/ui/impl-trait/two_tait_defining_each_other.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
// check-pass
|
||||
|
||||
type A = impl Foo;
|
||||
type B = impl Foo;
|
||||
|
||||
trait Foo {}
|
||||
|
||||
fn muh(x: A) -> B {
|
||||
if false {
|
||||
return Bar; // B's hidden type is Bar
|
||||
}
|
||||
x // A's hidden type is `Bar`, because all the hidden types of `B` are compared with each other
|
||||
}
|
||||
|
||||
struct Bar;
|
||||
impl Foo for Bar {}
|
||||
|
||||
fn main() {}
|
16
src/test/ui/impl-trait/two_tait_defining_each_other2.rs
Normal file
16
src/test/ui/impl-trait/two_tait_defining_each_other2.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
type A = impl Foo;
|
||||
//~^ ERROR could not find defining uses
|
||||
type B = impl Foo;
|
||||
|
||||
trait Foo {}
|
||||
|
||||
fn muh(x: A) -> B {
|
||||
x // B's hidden type is A (opaquely)
|
||||
}
|
||||
|
||||
struct Bar;
|
||||
impl Foo for Bar {}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,8 @@
|
|||
error: could not find defining uses
|
||||
--> $DIR/two_tait_defining_each_other2.rs:3:10
|
||||
|
|
||||
LL | type A = impl Foo;
|
||||
| ^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
20
src/test/ui/impl-trait/two_tait_defining_each_other3.rs
Normal file
20
src/test/ui/impl-trait/two_tait_defining_each_other3.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
// check-pass
|
||||
|
||||
type A = impl Foo;
|
||||
type B = impl Foo;
|
||||
|
||||
trait Foo {}
|
||||
|
||||
fn muh(x: A) -> B {
|
||||
if false {
|
||||
return x; // B's hidden type is A (opaquely)
|
||||
}
|
||||
Bar // A's hidden type is `Bar`, because all the return types are compared with each other
|
||||
}
|
||||
|
||||
struct Bar;
|
||||
impl Foo for Bar {}
|
||||
|
||||
fn main() {}
|
Loading…
Add table
Add a link
Reference in a new issue