From 5a374dc813c8c6a1d10b3c6cc7fdeaa9aafbcc65 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 26 Jan 2022 17:20:48 +0000 Subject: [PATCH] Add some tests to show what happens when you compare two opaque types that are both within the defining scope --- .../two_tait_defining_each_other.rs | 20 +++++++++++++++++++ .../two_tait_defining_each_other2.rs | 16 +++++++++++++++ .../two_tait_defining_each_other2.stderr | 8 ++++++++ .../two_tait_defining_each_other3.rs | 20 +++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 src/test/ui/impl-trait/two_tait_defining_each_other.rs create mode 100644 src/test/ui/impl-trait/two_tait_defining_each_other2.rs create mode 100644 src/test/ui/impl-trait/two_tait_defining_each_other2.stderr create mode 100644 src/test/ui/impl-trait/two_tait_defining_each_other3.rs diff --git a/src/test/ui/impl-trait/two_tait_defining_each_other.rs b/src/test/ui/impl-trait/two_tait_defining_each_other.rs new file mode 100644 index 000000000000..eb8d24832eb4 --- /dev/null +++ b/src/test/ui/impl-trait/two_tait_defining_each_other.rs @@ -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() {} diff --git a/src/test/ui/impl-trait/two_tait_defining_each_other2.rs b/src/test/ui/impl-trait/two_tait_defining_each_other2.rs new file mode 100644 index 000000000000..88a76089b82d --- /dev/null +++ b/src/test/ui/impl-trait/two_tait_defining_each_other2.rs @@ -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() {} diff --git a/src/test/ui/impl-trait/two_tait_defining_each_other2.stderr b/src/test/ui/impl-trait/two_tait_defining_each_other2.stderr new file mode 100644 index 000000000000..5a0cff527b6e --- /dev/null +++ b/src/test/ui/impl-trait/two_tait_defining_each_other2.stderr @@ -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 + diff --git a/src/test/ui/impl-trait/two_tait_defining_each_other3.rs b/src/test/ui/impl-trait/two_tait_defining_each_other3.rs new file mode 100644 index 000000000000..c289b43c4259 --- /dev/null +++ b/src/test/ui/impl-trait/two_tait_defining_each_other3.rs @@ -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() {}